Android : turn off already playing audio and play new audio

You must Login before you can answer or comment on any questions.

Hello,

I am working with a music player application in Android where I navigate to tracklist page.

When I choose a song from the trackList page, I need to turn off the already playing audio and play the new one.

As I am navigating from another page, a new audio player is created and the value for audio.playing is always false, which makes the newer auido play even when the old audio is playing.

The result is both the songs mixes together and irritates !!!!

I tried this ..

sound = Titanium.Media.createAudioPlayer({ allowBackground:true, audioSessionMode:Titanium.Media.AUDIO_SESSION_MODE_PLAYBACK, url:JSONdata[trackId][0].url });

         if(sound.playing){
            sound.reset();
            sound.stop();
           sound.start();
         }
        else{
            sound.start();
        }

As this audio player is created every time we enter this screen..the value for sound.playing is false always !!

Kindly help me..

Your Answer

Think you can help? Login to answer this question!