Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Why AudioPlayer crashes App?

$
0
0

Hi,

I have following code to play music using AudioPlayer control.

var win = Titanium.UI.createWindow({  
    title:'Audio Test',
    backgroundColor:'#fff',
    layout: 'vertical'
});
 
var startStopButton = Titanium.UI.createButton({
    title:'Start/Stop Streaming',
    top:10,
    width:200,
    height:40
});
 
var pauseResumeButton = Titanium.UI.createButton({
    title:'Pause/Resume Streaming',
    top:10,
    width:200,
    height:40,
    enabled:false
});
 
win.add(startStopButton);
win.add(pauseResumeButton);
 
// allowBackground: true on Android allows the 
// player to keep playing when the app is in the 
// background.
var audioPlayer = Ti.Media.createAudioPlayer({});
audioPlayer.url = '/cricket.wav';
 
startStopButton.addEventListener('click',function() {
    // When paused, playing returns false.
    // If both are false, playback is stopped.
    if (audioPlayer.playing || audioPlayer.paused)
    {
        audioPlayer.stop();
        pauseResumeButton.enabled = false;
        if (Ti.Platform.name === 'android')
        { 
            audioPlayer.release();
        }   
    }
    else
    {
        audioPlayer.start();
        pauseResumeButton.enabled = true;
    }
});
 
pauseResumeButton.addEventListener('click', function() {
    if (audioPlayer.paused) {
 
        audioPlayer.start();
    }
    else {
        audioPlayer.pause();
    }
});
 
audioPlayer.addEventListener('progress',function(e) {
    Ti.API.info('Time Played: ' + Math.round(e.progress) + ' milliseconds');
});
 
audioPlayer.addEventListener('change',function(e)
{
    Ti.API.info('State: ' + e.description + ' (' + e.state + ')');
});
 
win.addEventListener('close',function() {
    audioPlayer.stop();
    if (Ti.Platform.osname === 'android')
    { 
        audioPlayer.release();
    }
});
 
win.open();
My Environment:
  1. OS X 10.9
  2. Titanium Studion 3.2.0
  3. Titanium SDK: 3.2.0

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>