• Skip to content
  • Skip to link menu
KDE API Documentation - GCAudio.qml Source File (GCompris-qt)
  • KDE Home
  • Contact Us
 

GCompris-qt

  • src
  • core
GCAudio.qml
1 /* GCompris - GCAudio.qml
2  *
3  * Copyright (C) 2014 Johnny Jazeix <jazeix@gmail.com>
4  *
5  * Authors:
6  * Johnny Jazeix <jazeix@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, see <http://www.gnu.org/licenses/>.
20  */
21 import QtQuick 2.0
22 import QtMultimedia 5.0
23 import GCompris 1.0
24 
45 Item {
46  id: gcaudio
47 
52  property bool muted
53 
58  property alias source: audio.source
59 
64  property alias errorString: audio.errorString
65 
72  property var playbackState: (audio.error == Audio.NoError) ?
73  audio.playbackState : Audio.StoppedState;
74 
79  property var files: []
80 
84  signal error
85 
89  signal done
90 
95  onMutedChanged: muted ? audio.volume = 0 : audio.volume = 1
96 
104  function play(file) {
105  if(!fileId.exists(file) || muted)
106  return false
107 
108  if(file) {
109  // Setting the source to "" on Linux fix a case where the sound is no more played if you play twice the same sound in a row
110  source = ""
111  source = file
112  }
113  if(!muted) {
114  audio.play()
115  }
116  return true
117  }
118 
122  function stop() {
123  if(audio.playbackState != Audio.StoppedState)
124  audio.stop()
125  }
126 
138  function append(file) {
139  if(!fileId.exists(file) || muted)
140  return false
141 
142  if(audio.playbackState !== Audio.PlayingState
143  || audio.status === Audio.EndOfMedia
144  || audio.status === Audio.NoMedia
145  || audio.status === Audio.InvalidMedia) {
146  // Setting the source to "" on Linux fix a case where the sound is no more played
147  source = ""
148  source = file
149  audio.play()
150  } else {
151  files.push(file)
152  }
153  return true
154  }
155 
161  function silence(duration_ms) {
162  silenceTimer.interval = duration_ms
163  }
164 
169  function clearQueue() {
170  while(files.length > 0) {
171  files.pop();
172  }
173  }
174 
176 
177  function _playNextFile() {
178  var nextFile = files.shift()
179  if(!nextFile || 0 === nextFile.length) {
180  audio.source = ""
181  gcaudio.done()
182  } else {
183  audio.source = ""
184  audio.source = nextFile
185  if(!muted)
186  audio.play()
187  }
188  }
189 
190  Audio {
191  id: audio
192  onError: {
193  // This file cannot be played, remove it from the source asap
194  source = ""
195  if(files.length)
196  silenceTimer.start()
197  else
198  gcaudio.error()
199  }
200  onStopped: {
201  if(files.length)
202  silenceTimer.start()
203  else
204  gcaudio.done()
205  }
206  }
207 
208  Timer {
209  id: silenceTimer
210  repeat: false
211  onTriggered: {
212  interval = 0
213  _playNextFile()
214  }
215  }
216 
217  File {
218  id: fileId
219  }
220 
222 
223 }
QtMultimedia
QtQuick
GCompris
File
A helper component for accessing local files from QML.
Definition: File.h:34
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Tue Jun 2 2015 21:47:47 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

GCompris-qt

Skip menu "GCompris-qt"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List
  • Modules

Class Picker

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal