Problem description
When playing a sound downloaded in the application data directory, on certain devices (e.g. HTC Desire HD) the sound doesn't play. Everything works fine with other devices, or with the same device using the external directory.
Steps to reproduce
Use this code to reproduce the issue:
// Create a window
var win = Ti.UI.createWindow({
backgroundColor : 'white',
layout: 'vertical'
});
function download() {
var xhr = Ti.Network.createHTTPClient({
onload: function() {
var data = this.responseData;
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'test.mp3');
file.write(data);
alert("File downloaded");
}
});
xhr.open('GET', '[MP3 URL HERE]');
xhr.send();
}
function play() {
// load from application directory
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'test.mp3');
Ti.API.info(file.nativePath);
var sound = Titanium.Media.createSound({url:file.nativePath});
sound.play();
sound.addEventListener('error', function(e) {
dialog = Ti.UI.createAlertDialog({
message : "Audio playback failed",
buttonNames : ['OK']
});
dialog.show();
});
}
var btn1 = Ti.UI.createButton({
title: "Download"
});
btn1.addEventListener('click', download);
var btn2 = Ti.UI.createButton({
title: "Play"
});
btn2.addEventListener('click', play);
win.add(btn1);
win.add(btn2);
win.open();
Running the code on HTC devices does not play the sound.
Tested with a HTC Desire HD and attaching a log file.
Also, does this happen with all sound files or just ones of a certain type?
device specific jithinpv
Based on the [doc](http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.Filesystem-property-applicationDataDirectory), the sound file in the application data directory cannot be accessed by the android media player which is “another” application and requires world-readable permissions for the application’s local media files. “World-readable” means another application can see it. Therefore, the downloaded sound file should be stored in externalStorageDirectory if the user wants to play it. Mark the ticket as invalid.
I have the same issue in the Galaxy Nexus device. [ERROR] : MediaPlayer: error (1, -2147483648)
Closing ticket as invalid.