Audio Issue. Can't play wav file


#1

Hi guys, I can’t play this wav file in my domain the first time it’s loaded:

https://dl.dropboxusercontent.com/u/7497773/buonaseraRagazzi.wav

I used Online converter (http://www.online-convert.com/) do convert it from mp3 to wav 16bit/48kHz/mono (PCM S16 LE (s16l)).

I’ve an entity and If I enter into it I want play the wav audio:

this.enterEntity = function(entityID) {
   audioCiao = SoundCache.getSound('https://dl.dropboxusercontent.com/u/7497773/buonaseraRagazzi.wav');
   Audio.playSound(audioCiao, { position: MyAvatar.position, volume: 0.8 });   
};

The first time I get into it, the progression bar appears and the log says:
[07/15 17:48:54] [DEBUG] Requesting sound at “https://dl.dropboxusercontent.com/u/7497773/buonaseraRagazzi.wav
[07/15 17:48:54] [DEBUG] Starting request for: https://dl.dropboxusercontent.com/u/7497773/buonaseraRagazzi.wav
[07/15 17:48:54] [DEBUG] AudioInjector::injectNextFrame() called with no samples to inject. Returning.

The SECOND time I get into it, it plays the wav audio :confused:


#2

You must play if and only if the file is downloaded.

Run an if conditional on audioCiao.dowloaded?(playsound):(checklater)

Keep in mind that if you only check once… then it will not check again…

protip: setInterval is your friend.


#3

I made, i noticved a few days ago i lazy solution. i made a 5 seconds delay before i start to play. I need to update that someday.

And yes, if you start play before it’s loaded. it’s not playing :frowning: Why does High Fidelity not have a that build in the code. SO users not need todo that check ?


#4

hi @gorgo,

You have to preload the sound. audioCiao will not play if it is not completely loaded yet. Try using the preload function of your entity prototype/object to get the sound file from the soundCache.

Example

var yourSoundFileURL = "https://dl.dropboxusercontent.com/u/14997455/hifi/42900__freqman__glass-break-2-2.wav";

var yourInjector = null;

var yourSound = SoundCache.getSound(yourSoundFileURL);

var yourSoundPlayFunction = function() {
    print('The sound should be playing here');
    yourInjector = Audio.playSound(yourSound, { position: MyAvatar.position, volume: 0.8 });
};

if (yourSound.downloaded) {
    yourSoundPlayFunction();
} else {
    yourSound.ready.connect(yourSoundPlayFunction);
}

/// The following part goes in your unload, be sure that the lifetime of your entity is longer then your clip, otherwise unload will be called right after you play the sound-file:

if (yourInjector !== null && yourInjector.isPlaying()) {
    yourInjector.stop();
}