Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6962] Android: Media - AudioPlayer continues downloading the file even after stop or destroying the object

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionInvalid
Resolution Date2012-02-10T00:06:27.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelstc-more-info
ReporterMauro Parra-Miranda
AssigneeOpie Cyrus
Created2011-12-29T23:02:09.000+0000
Updated2012-02-10T00:06:27.000+0000

Description

PROBLEM DESCRIPTION

If you create an AudioPlayer, it will continue downloading the file, even if you stop the player, or actually even if you destroy the player.

EXPECTED RESULTS

If the AudioPlayer is set to null, should not continue downloading the file while waiting for Garbage collecting.

ACTUAL RESULTS

The player continues downloading the file, even if was set to null.

TEST CASE

Paste the code into app.js

Run it into Android

Press Play. Check the message "General Available Memory".

Pause the player. You will see that the General Available Memory it will be down by 24 bytes (or so), each 5 seconds.

Press "Delete" button. The player will be set to null.

var win = Titanium.UI.createWindow();

var sound = Titanium.Media.createAudioPlayer({url:'http://www.wav-sounds.com/answering_machine/rappin.wav'});

sound.addEventListener('progress',function(){
	Ti.API.info("Available Memory:"+Ti.Platform.getAvailableMemory());
});

//
// PLAY
//
var play = Titanium.UI.createButton({
	title:'Play',
	height:40,
	width:145,
	left:10,
	top:10
});
play.addEventListener('click', function()
{
	sound.play();
});
win.add(play);

//
// PAUSE
//
var pause = Titanium.UI.createButton({
	title:'Pause',
	height:40,
	width:145,
	right:10,
	top:10
});
pause.addEventListener('click', function()
{
	sound.pause();
});
win.add(pause);

//
// STOP
//
var stop = Titanium.UI.createButton({
	title:'Stop',
	height:40,
	width:145,
	right:10,
	top:60
});
stop.addEventListener('click', function()
{
	sound.stop();
});
win.add(stop);

var bdelete = Titanium.UI.createButton({
	title:'Delete',
	height:40,
	width:145,
	left:10,
	top:60
});
bdelete.addEventListener('click', function()
{
	sound = null; 
});
win.add(bdelete);

setInterval(function(){
	Ti.API.info("General Available Memory:"+Ti.Platform.getAvailableMemory());
	}, 5000);

win.open();

Comments

  1. Paul Dowsett 2011-12-30

    Mauro, thanks for raising this. Would you please complete the environment field, in accordance with the [JIRA Ticket Checklist](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-JIRATicketChecklist)? Then I can move this to the main project. Thank you
  2. Neeraj Gupta 2012-01-03

    We should not put "community" as a customer as many of our bugs are reported by community and this field indicates customer priority issues.
  3. Opie Cyrus 2012-01-06

    There is a fix for this ticket being made which addresses the failure of calls to destroy() not actually stopping the download for remote source. That having been said, setting the player to null is not a valid mechanism for stopping the active media player. A developer should call destroy() in order to shutdown the player correctly rather than just setting the player to null. When pausing the player, the media player implementation itself within Android may continue to buffer content which can explain the the memory footprint described . When testing the change, please change the handle for the "Destroy" button click to:
       sound.destroy();
       sound = null; 
       
  4. Opie Cyrus 2012-01-06

    Upon further review, there is actually no platform change required. Against current master, the memory foot print behaves correctly when calling release() on the AudioPlayer without any additional changes. Please use release() rather than destroy() mentioned above as this is more consistent with the the other player management calls on Android.
  5. Mauro Parra-Miranda 2012-01-06

  6. Opie Cyrus 2012-01-06

    It should also be noted that there is an upcoming fix for general GC behavior but as you cannot guarantee when a GC occurs, this behavior (setting player to null) should not be depended upon for shutting down media players and cleaning up resources. It should be noted that on V8, when the player is released the reported footprint stays almost completely static (droid2 2.2).

JSON Source