Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12020] Android: audio file in application data directory does not play on certain devices

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2013-03-21T01:33:09.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 06 API, 2013 Sprint 06
ComponentsAndroid
Labelsn/a
ReporterDavide Cassenti
AssigneePing Wang
Created2012-12-11T12:30:57.000+0000
Updated2017-03-21T19:17:38.000+0000

Description

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.

Attachments

FileDateSize
log.txt2012-12-18T12:39:51.000+00003544

Comments

  1. Betty Tran 2012-12-18

    Tested with a HTC Desire HD and attaching a log file.
  2. Ingo Muschenetz 2013-01-03

    Also, does this happen with all sound files or just ones of a certain type?
  3. jithinpv 2013-03-15

    device specific jithinpv
  4. Ping Wang 2013-03-21

    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.
  5. Eduardo Silva 2014-11-03

    I have the same issue in the Galaxy Nexus device. [ERROR] : MediaPlayer: error (1, -2147483648)
  6. Lee Morris 2017-03-21

    Closing ticket as invalid.

JSON Source