Community
cancel
Showing results for 
Search instead for 
Did you mean: 
staurt_s_
Beginner
49 Views

Media Plugin not working iOS

Hi Everyone,

I am trying to get a simple mp3 file to play on iOS (2 sec bell sound) and I can not get it to work at all, for 3 days I have tested, read forms, changed code and I can not get to work, the main error I get is "Cannot use audio file from resource", I tried .ogg .mp3 .wav and nothing.

I am using

Media Version 2.2.0

Cordova CLI 5.4.1

I have tried using full location, full href, persistant file system, localhost, etc

When in the emulator and reference locally it works fine

Has anyone manage to get it working on iOS 9.2

Thanks

Tags (2)
0 Kudos
5 Replies
PaulF_IntelCorp
Employee
49 Views

Try experimenting with the "Audio Play App" first. In the "Samples and Demos" section of the XDK ("Open a New Project").

0 Kudos
staurt_s_
Beginner
49 Views

Hi,

I took the code from the demo and still the same, works fine on Android but not on iOS.

I see many people around having the same issue with Cordova.

var PlayCordovaAudio = function(src) {
    "use strict";
    var x = navigator.userAgent;
    var z = getWebRoot();

    if (window.cordova && cordova.file) {// if Cordova file plugin present
        if (!(/^https?:/i.test(src))) {// if local file to be played...
            if (x.match(/(ios)|(iphone)|(ipod)|(ipad)/ig)) {// if on iOS device...
                if (window.tinyHippos)// ...AND in the Emulate tab
                    src = z + "/" + src;
                // correct file location for Emulate tab
            } else// for everything else...
                src = z + "/" + src;
            // add absolute path prefix on non-iOS
        }
        mymedia = new Media(src,
            function () { console.log("playAudio():Audio Success"); },
            function (err) { console.log("playAudio():Audio Error: " + err.message); }                   
        );
        mymedia.play();
    }
};
var getWebRoot = function() {
    "use strict" ;
    var path = window.location.href ;
    path = path.substring( 0, path.lastIndexOf('/') ) ;
    return path ;
};

Here is the code, Any ideas

0 Kudos
PaulF_IntelCorp
Employee
49 Views

Double-check the CSP directives in your index.html file, this is especially important on iOS 9 devices. See the CSP directive in that audio app for an example.

0 Kudos
staurt_s_
Beginner
49 Views

Hi,

I added CSP

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: blob: filesystem: ws: gap: cdvfile: http://travelon.world https://*.getfirebug.com http://*.openstreetmap.org http://debug-software.intel.com ; style-src 'self' 'unsafe-inline' ; ">

and still the same result, what am I missing?

Thanks

0 Kudos
PaulF_IntelCorp
Employee
49 Views

Are you able to make it work by modifying the Audio App to use your media files rather than the ones built into the Audio App? That would be a simpler test. If that works, then compare the differences between the two.

0 Kudos