Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18297] Android: On Lollipop AudioPlayer not playing after stopping stream and restarting it

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2019-10-04T13:48:37.000+0000
Affected Version/sn/a
Fix Version/sRelease 8.3.0
ComponentsAndroid
Labelsandroid
ReporterAshraf Abu
AssigneeGary Mathews
Created2014-12-30T05:18:44.000+0000
Updated2019-10-04T13:48:37.000+0000

Description

When Audio Player is interrupted mid play and stopped, it cannot start again. This occurs on Nexus 6 with Android 5.0 Lollipop. Code as follows:
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({ 
    url: 'https://ia902508.us.archive.org/5/items/testmp3testfile/mpthreetest.mp3',
    allowBackground: true
});           
    
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();
Logs as follows:
[WARN] :   V8Object: (KrollRuntimeThread) [81,81] Runtime disposed, cannot set property 'userAgent'
[INFO] :   TiRootActivity: (main) [0,0] checkpoint, on root activity resume. activity = text.com.NewtestActivity@3ad081fa
[INFO] :   Adreno: EGLInit: QTI Build: 10/14/14, 40a273b, I86da836d38
[INFO] :   OpenGLRenderer: Initialized EGL, version 1.4
[INFO] :   State: starting (4)
[ERROR] :  MediaPlayer: Should have subtitle controller already set
[INFO] :   State: initialized (1)
[INFO] :   State: playing (3)
[INFO] :   Time Played: 1332 milliseconds
[INFO] :   Time Played: 2351 milliseconds
[INFO] :   Time Played: 3370 milliseconds
[INFO] :   Time Played: 4310 milliseconds
[INFO] :   Time Played: 5329 milliseconds
[INFO] :   Time Played: 6348 milliseconds
[INFO] :   Time Played: 7367 milliseconds
[INFO] :   Time Played: 8307 milliseconds
[INFO] :   Time Played: 9326 milliseconds
[INFO] :   Time Played: 10344 milliseconds
[INFO] :   Time Played: 11363 milliseconds
[INFO] :   Time Played: 12330 milliseconds
[INFO] :   State: playing (3)
[INFO] :   Time Played: 1332 milliseconds
[INFO] :   Time Played: 2351 milliseconds
[INFO] :   State: stopping (6)
[INFO] :   State: stopped (5)
[WARN] :   MediaPlayer: mediaplayer went away with unhandled events
[INFO] :   State: starting (4)
[INFO] :   APSAnalyticsService: Analytics Service Started
[INFO] :   APSAnalyticsService: Stopping Analytics Service
[ERROR] :  MediaPlayer: error (1, -2147483648)
[ERROR] :  MediaPlayer: Error (1,-2147483648)

Comments

  1. Ian Thomas 2015-01-11

    This also happens on Nexus 7 (2012) with Android 5.0.2. I have found that if you clear the app data cache, you can attempt to play the audio file again. If you don't, you can never play the audio file again. Because of this, it appears there is a bug with AudioPlayer.release().
  2. Frank Eijking 2015-04-16

    For a Nexus 6, I worked around the issue, by each time adding a timestamp to the stream url. This works on a Nexus 6 with Android 5.1. (tested with Ti 3.5.1.GA). On Android 5.0.1. with a Samsung Galaxy S4 with an app compiled with Ti 3.5.1.GA this also works, however, it takes about 10 seconds(!) before the stream initializes and starts playing. Same app package installed on the same device with Android 4.4 starts shoutcast stream playback immediately. It looks like the good old Android 2.2 behavior is back... at least for Android 5.0.1. on a Samsung Galaxy S4.
  3. Frank Eijking 2015-04-16

  4. Wouter Versluijs 2015-09-03

    Is there any update on this ticket? This issue still seems to be in effect on the Android M Beta, but even worse. When I use the audioPlayer to play a webstream (ie. http://eu7.fastcast4u.com:8128/stream) it won't play at all on Android M (LG Nexus 5). All I get is the following error "Unknown media error". Also adding a cache buster behind the url, it won't work. When playing normal .mp3 files from the web it does work. *Please note* that this seems to work on Android 5.0.1 (Samsung Galaxy S4) and all versions prior to that.
  5. Michael Gangolf 2019-03-23

    PR: https://github.com/appcelerator/titanium_mobile/pull/10800
  6. Satyam Sekhri 2019-09-16

    FR passed. Audio player works fine upon resume or restart. Also no warnings shown.
  7. Sohail Saddique 2019-10-04

    *FR Passed* Test environment: Studio Ver: 5.1.4.201909061933 SDK Ver: 8.3.0.v20191003144543 OS Ver: 10.14.6 Appc NPM: 4.2.15 Appc CLI: 7.1.1 Node Ver: 10.16.3 NPM Ver: 6.11.3 Emulator: ⇨ Android 5.1.1 (Nexus 6 - Lollipop) Ticket closed.

JSON Source