Commit f085d77f authored by Bruno Coudoin's avatar Bruno Coudoin
Browse files

audio and click_on_letter

Added a silence(duration_ms) function in GCAudio to force
a silence before the play of the next audio file

Fixed references to isAudioEnabled

Changed click_on_letter to use the global GCAudio and the new silence
function (not very well tested)
parent 7594a040
......@@ -54,15 +54,14 @@ ActivityBase {
id: items
property alias bar: bar
property alias trainModel: trainModel
property alias nextLevelAudio: nextLevelAudio
property GCAudio audioVoices: activity.audioVoices
property alias parser: parser
property alias letterAudio: letterAudio
property alias questionItem: questionItem
property alias score: score
property alias bonus: bonus
}
onStart: Activity.start(items, mode, activity.audio);
onStart: Activity.start(items, mode);
onStop: Activity.stop()
......@@ -87,8 +86,8 @@ ActivityBase {
onPreviousLevelClicked: Activity.previousLevel()
onNextLevelClicked: Activity.nextLevel()
onHomeClicked: home()
onRepeatClicked: if (ApplicationSettings.isAudioEnabled)
letterAudio.playLetterDelayed(Activity.currentLetter, 0);
onRepeatClicked: if (ApplicationSettings.isAudioVoicesEnabled)
Activity.playLetter(Activity.currentLetter);
}
Score {
......@@ -229,42 +228,5 @@ ActivityBase {
onError: console.error("Click_on_letter: Error parsing JSON: " + msg);
}
GCAudio {
id: nextLevelAudio
source: ApplicationInfo.getAudioFilePath("voices/$LOCALE/misc/click_on_letter.ogg")
onError: letterAudio.play()
// When this sound is complete, play the letter
onDone: letterAudio.playLetterDelayed(Activity.currentLetter, 100);
}
GCAudio {
id: letterAudio
onError: questionItem.visible = true
function playLetterDelayed(letter, ms) {
if (letterAudioTimer.running)
letterAudioTimer.stop();
letterAudio.source = ApplicationInfo.getAudioFilePath("voices/$LOCALE/alphabet/"
+ Core.getSoundFilenamForChar(letter));
if (ms != 0) {
letterAudioTimer.interval = ms;
letterAudioTimer.start();
} else {
if (letterAudio.playbackState != Audio.StoppedState)
letterAudio.stop();
letterAudio.play();
}
}
}
Timer {
id: letterAudioTimer
repeat: false
onTriggered: {
if (letterAudio.playbackState != Audio.StoppedState)
letterAudio.stop();
letterAudio.play();
}
}
}
}
......@@ -41,16 +41,13 @@ var questions;
var answers;
var items;
var mode;
var mainAudio
function start(_items, _mode, _mainAudio)
function start(_items, _mode)
{
Core.checkForVoices(_items.bar);
_items.nextLevelAudio.source = GCompris.ApplicationInfo.getAudioFilePath("voices/$LOCALE/misc/click_on_letter.ogg");
items = _items;
mode = _mode;
mainAudio = _mainAudio;
loadLevels();
currentLevel = 0;
......@@ -143,19 +140,14 @@ function initLevel() {
}
currentLetter = questions.split("")[currentSubLevel];
if (GCompris.ApplicationSettings.isAudioEnabled &&
GCompris.DownloadManager.haveLocalResource(
if (GCompris.ApplicationSettings.isAudioVoicesEnabled &&
GCompris.DownloadManager.haveLocalResource(
GCompris.DownloadManager.getVoicesResourceForLocale(
GCompris.ApplicationInfo.localeShort))) {
items.nextLevelAudio.stop();
if (mainAudio.playbackState === Multimedia.Audio.PlayingState)
mainAudio.onDone.connect(function () {
items.nextLevelAudio.play();
});
else
items.nextLevelAudio.play();
items.questionItem.visible = false;
GCompris.ApplicationInfo.localeShort))) {
items.audioVoices.append(GCompris.ApplicationInfo.getAudioFilePath("voices/$LOCALE/misc/click_on_letter.ogg"));
items.audioVoices.silence(100)
playLetter(currentLetter)
items.questionItem.visible = false
} else {
// no sound -> show question
items.questionItem.visible = true;
......@@ -164,6 +156,11 @@ function initLevel() {
items.questionItem.text = currentLetter;
}
function playLetter(letter) {
items.audioVoices.append(GCompris.ApplicationInfo.getAudioFilePath("voices/$LOCALE/alphabet/"
+ Core.getSoundFilenamForChar(letter)))
}
function nextLevel() {
if(maxLevel <= ++currentLevel ) {
currentLevel = 0
......@@ -191,7 +188,7 @@ function nextSubLevel() {
function checkAnswer(index)
{
var modelEntry = items.trainModel.get(index);
items.letterAudio.playLetterDelayed(modelEntry.letter, 0);
playLetter(modelEntry.letter);
if (modelEntry.letter == currentLetter) {
items.bonus.good("flower");
return true
......
......@@ -121,7 +121,7 @@ ActivityBase {
onPreviousLevelClicked: Activity.previousLevel()
onNextLevelClicked: Activity.nextLevel()
onHomeClicked: activity.home()
onRepeatClicked: if (ApplicationSettings.isAudioEnabled)
onRepeatClicked: if (ApplicationSettings.isAudioVoicesEnabled)
questionItem.initQuestion()
}
......
......@@ -479,7 +479,7 @@ Rectangle {
function hasConfigChanged() {
return (ApplicationSettings.locale != languages.get(languageBox.currentIndex).locale ||
(ApplicationSettings.isAudioEnabled != isAudioVoicesEnabled) ||
(ApplicationSettings.isAudioVoicesEnabled != isAudioVoicesEnabled) ||
(ApplicationSettings.isFullscreen != isFullscreen) ||
(ApplicationSettings.isVirtualKeyboard != isVirtualKeyboard) ||
(ApplicationSettings.isAutomaticDownloadsEnabled != isAutomaticDownloadsEnabled)
......
......@@ -24,7 +24,7 @@ import GCompris 1.0
Item {
id: gcaudio
property bool muted: !ApplicationSettings.isAudioEnabled
property bool muted
property alias source: audio.source
property alias errorString: audio.errorString
......@@ -62,20 +62,45 @@ Item {
}
// Add the given duration in ms before the play of the next file
function silence(duration_ms) {
silenceTimer.interval = duration_ms
}
function _playNextFile() {
var nextFile = files.shift()
if(nextFile) {
audio.source = nextFile
audio.play()
} else
gcaudio.done()
}
Audio {
id: audio
autoPlay: gcaudio.autoPlay && !gcaudio.muted
onError: {
console.log("error while playing: " + source + ": " + errorString)
gcaudio.error()
if(files.length)
_playNextFile()
else
gcaudio.error()
}
onStopped: {
var nextFile = files.shift()
if(nextFile) {
source = nextFile
play()
} else
gcaudio.done()
if(silenceTimer.interval)
silenceTimer.start()
else
_playNextFile()
}
}
Timer {
id: silenceTimer
repeat: false
onTriggered: {
interval = 0
_playNextFile()
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment