Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24024] TIMOB8418 Music won't stop playing after exiting

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2016-11-10T19:23:16.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterLee Morris
AssigneeFarzad Merzadyan
Created2016-10-12T22:50:50.000+0000
Updated2016-11-10T19:23:20.000+0000

Description

For TIMOB8418, the app plays Dancing in the Street by Martha and the Vandellas. However, there is no way to stop the music playing. The track just carries on and you have to kill the Media Module application to stop it playing. This occurs on iOS (10.) and Android devices (6.0.1). App.js
function askCalendarPermission(){
	if (Ti.Calendar.hasCalendarPermissions()) {
		Ti.Calendar.getAllCalendars();
		askContactPermission();	      	
	    } else {
	       Ti.Calendar.requestCalendarPermissions(function(e) {
	           if (e.success === true) {
	              Ti.API.info("Calendar Permissions Granted");
	              Ti.Calendar.getAllCalendars();
	              askContactPermission();
	           } else {
	              alert("Access denied, error: " + e.error);
	           }
	       });
	    }
}

function askContactPermission(){
	if (Ti.Contacts.hasContactsPermissions()) {
			Ti.Contacts.getAllPeople();
	       askCameraPermissions(); 
	    } else {
	       Ti.Contacts.requestContactsPermissions(function(e) {
	           if (e.success === true) { 
	           	  Ti.API.info("Contacts Permissions Granted");
	           	  Ti.Contacts.getAllPeople();
	              askCameraPermissions(); 
	           } else {
	              alert("Access denied, error: " + e.error);
	           }
	       });
	    }
}

//Added camera permissions in the tiapp.xml for camera because permissions get added to the android manifest only if showCamera() is called below. But its not fesible here as opening a camera before app launches just to add camera permissions looks stupid.
function askCameraPermissions(){
if (Ti.Media.hasCameraPermissions()) {
       require('ui').createApplicationTabGroup().open();    
   } else { 
       Ti.Media.requestCameraPermissions(function(e) {
                if (e.success === true) {
                	Ti.API.info("Camera Permissions Granted");
                    require('ui').createApplicationTabGroup().open();
                } else {
                    alert("Access denied, error: " + e.error);
                }
       });
   }
}

askCalendarPermission();

Attachments

FileDateSize
code TIMOB8418.docx2016-10-12T22:48:29.000+000070497
screenshot-1.png2016-10-13T20:12:33.000+000046789

Comments

  1. Hans Knöchel 2016-10-13

    Please provide a reproducible demo-code (best in a single app.js), thank you!
  2. Hans Knöchel 2016-10-25

    [~lmorris] The provided code is not related to this ticket (it's related to permissions in general), can you change it to the one you specified in your image?
  3. Farzad Merzadyan 2016-10-25

    Speaking for Android (not sure about iOS): Looks like setting allowBackground property, in Ti.Media.createAudioPlayer, to false does not stop audio when app is exited. The audio can be stopped or resumed by calling audioPlayer.stop() via button click and also the audio can be stopped if app is destroyed from open apps slider.
  4. Farzad Merzadyan 2016-10-26

    [~hansknoechel] This is what I have for app.js. You need to download a supported sound file and change the url:
       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({
       	allowBackground: true,
       	url: 'sample.mp3'
       });
       
       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();
       
       

JSON Source