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();
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
We should not put "community" as a customer as many of our bugs are reported by community and this field indicates customer priority issues.
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:
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.
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).