You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Markus Sorg (JIRA)" <ji...@apache.org> on 2014/06/24 15:19:25 UTC

[jira] [Commented] (CB-7007) iOS Media Plugin: mp3 does not play

    [ https://issues.apache.org/jira/browse/CB-7007?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14042090#comment-14042090 ] 

Markus Sorg commented on CB-7007:
---------------------------------

Hey,

the problem with iOS is that the media plugin doesn't support file urls like this (Android does):

{code:borderStyle=solid} 
file:///var/mobile/Applications/0C73C60B-07FD-486D-8927-7568D8BBBFD2/Library/files/app-data/main-packages/en/2.mp3
{code}

The trick on iOS AND Android is to use .toInternalURL() instead of .toURL() on the file object. This code will work perfectly on both platforms:

{code:borderStyle=solid}
window.requestFileSystem(
    LocalFileSystem.PERSISTENT,
    0,
    function(fileSystem) {
        fileSystem.root.getDirectory('app-data/main-packages/en/', {create: false}, function(sourceDir){
            sourceDir.getFile('2.mp3', {create: false}, function(file){
                console.log('file url: ', file.toInternalURL());
                var mymedia = new Media(file.toInternalURL()); 
                mymedia.play();
            });
        });
    },
    function(err){
        console.log('Error in requestFilesystem, err.code', err.code);                    
    }
);
{code}

.toInternalURL() will map to the following file path internally:

{code:borderStyle=solid}
iOS/Android: cdvfile://localhost/persistent/app-data/main-packages/en/2.mp3
{code}

Unfortunately the different behavior of the plugin when passing in file urls for Android/iOS is not documented on the plugin github page. 

> iOS Media Plugin: mp3 does not play
> -----------------------------------
>
>                 Key: CB-7007
>                 URL: https://issues.apache.org/jira/browse/CB-7007
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS, Plugin File, Plugin Media
>    Affects Versions: 3.5.0
>            Reporter: Markus Sorg
>              Labels: media, mp3
>
> Hello,
> I have a file named 2.mp3 in the folder APP_DIR/Library/files/app-data/main-packages/en/. My persistent file storage location is configured in config.xml ("Library" for iOS):
> {code:borderStyle=solid}<preference name="AndroidPersistentFileLocation" value="Internal" />
> <preference name="iosPersistentFileLocation" value="Library" />{code}
> This code will play the file perfectly on Android but not on iOS:
> {code:borderStyle=solid}
> window.requestFileSystem(
>     LocalFileSystem.PERSISTENT,
>     0,
>     function(fileSystem) {
>         fileSystem.root.getDirectory('app-data/main-packages/en/', {create: false}, function(sourceDir){
>             sourceDir.getFile('2.mp3', {create: false}, function(file){
>                 console.log('file url: ', file.toURL());
>                 var mymedia = new Media(file.toURL()); 
>                 mymedia.play();
>             });
>         });
>     },
>     function(err){
>         console.log('Error in requestFilesystem, err.code', err.code);                    
>     }
> );
> {code}
> The console.log() in the getFile callback will output the following files:
> {code:borderStyle=solid}
> Simulator: file:///Users/myUserName/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/9CE5380D-2B6C-461D-8902-071EFE8A1E70/Library/files/app-data/main-packages/en/2.mp3
> Device: 
> file:///var/mobile/Applications/0C73C60B-07FD-486D-8927-7568D8BBBFD2/Library/files/app-data/main-packages/en/2.mp3
> {code}
> The files definitely exist at these locations, but I get the following error:
> {code:borderStyle=solid}
> 2014-06-23 17:10:10.599 nnn[17439:60b] Unknown resource 'file:///Users/myUserName/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/9CE5380D-2B6C-461D-8902-071EFE8A1E70/Library/files/app-data/main-packages/en/2.mp3'
> {code}
> If I put the same file in the app documents folder and trigger the Media plugin with the following code it will play:
> {code:borderStyle=solid}
> var myMedia = new Media('documents://2.mp3');
> myMedia.play();
> {code}
> I also tried to call the Media Plugin with the "cdvfile"- Syntax. But it doesn't play either:
> {code:borderStyle=solid}
> var myMedia = new Media('cdvfile://Users/myUserName/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/9CE5380D-2B6C-461D-8902-071EFE8A1E70/Library/files/app-data/main-packages/en/2.mp3');
> myMedia.play();
> {code}
> I'm running on the following Plugin versions:
> {code:borderStyle=solid}
> file: 1.1.0
> media: 0.2.11
> {code}
> Any ideas ? 
> Thanks in advance,
> Markus



--
This message was sent by Atlassian JIRA
(v6.2#6252)