PhoneGap Media - No Audio Playing in Ion

7 posts, 0 answers
  1. David
    David avatar
    5 posts
    Member since:
    Aug 2013

    Posted 07 Jan 2014 Link to this post

    Greetings folks.

    Had anyone had any issue with trying to play audio in Ion using the PhoneGap Media API?

    I'm using a simple .mp3 file and it works fine in the Simulator in Graphite, but is failing when I load the app in Ion. I have not yet tested on an android device, but will do that next.

    I can also say that when I looked at the Media sample, it was referencing an MP3 on the internet. So I changed my variable to use that path and it does work on Ion when I reference an internet URL. Although I seem to have to press play twice for it to work..shrug maybe delay in pulling down the MP3 file.

    Anyhow, I used the following code to ensure it's got the correct file in the project:
    if (device.platform == "Android") {
        src = new Media("/android_asset/www/audio.mp3");
    else {
        src = new Media("audio.mp3");
    }

    Any ideas on why it might be doing that? I've tried to do as much debugging in Graphite as possible, but kinda lost for how to debug on the device itself, other then a few popups making sure the object is there, etc.

    Since I have it working fine when calling an internet URL to an mp3, I have to assume its the way the file is stored. Is there a way to detect if the file is in the download package? I have the file at the root of my project and not in any subfolders. Figured that was safest to start out with and get working.

    Thanks in advance. :)
  2. David
    David avatar
    5 posts
    Member since:
    Aug 2013

    Posted 07 Jan 2014 Link to this post

    Update:

    Well, I've been able to use the window.location.pathname in an alert to identify exactly the location of my root .html file. I've take that path and am passing that full path into the "Media()" function. That seems to work, but it seems like its not necessary and/or not possible in a production env:

    "/var/mobile/Applications/D7A2D78F-EA8A-44BC-9230-65DAF732A049/Documents/filename.mp3"

    Correct me if I'm wrong, but won't that GUID be dynamically generated and not something I can rely on inside my code?

    I'm glad that it's working, but this doesn't seem to be best practice or recommended or reliable...lol.

    Thanks again in advance! :)
  3. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 10 Jan 2014 Link to this post

    Hi David,

    Icenium ION is a container app, so the path of your files when deploying to ION is different than the actual path of your app when deployed on iOS. With that said, the behavior you observe is expected and if you need to test local audio files in ION, you can use the approach you've found.

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  4. David
    David avatar
    5 posts
    Member since:
    Aug 2013

    Posted 10 Jan 2014 Link to this post

    Steve,

    Thanks for the reply. So is your recommendation then to stick with the original if/else I had in my original post or if it is better to use an approach where you dynamically identify the path at runtime on the device, such as:

        app.getPhoneGapPath = function() {

               //alert('enter path function');
        var path = window.location.pathname;
            //alert('before substr: ' + path);
        path = path.substr( 0, path.length - 10 );
        //alert(path);
        //return 'file://' + path;
            return path;

    };



    Thanks :)
  5. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 13 Jan 2014 Link to this post

    Hello David,

    The check for device OS from your first post is a valid approach and the paths for Android/iOS when your app is deployed would respect it. You can find more information why this is required in the following blog post.

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  6. David
    David avatar
    5 posts
    Member since:
    Aug 2013

    Posted 13 Jan 2014 Link to this post

    Steve,

    Thanks again for the response. It just makes it hard to test with ion, if the audio doesn't work. I suppose if you go with the first method, then you would just want to do maybe a search and replace on your file path for non-android, put in the hardcoded string, test and then before you publish to the app store, then replace it back with the correct string?

    That just seems ready for mistakes to run free..lol. So with that in mind, is there anything wrong with the approach I found where it is dynamically found at run time?

    Thanks again,

    David
  7. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 14 Jan 2014 Link to this post

    Hello David,

    ION is a helper utility that we've created, so you could test an app under iOS in the early stages before you commit to the Apple Dev program. It is not a replacement to testing the app with appropriate provision nor it is intended for distribution usage to your testers. There are also other limitations like not being able to run custom Cordova plugins in ION.

    With that said, the idea behind ION is not full testing/debugging of your app, but just getting an idea whether your app looks like intended/designed. We recommend full testing of your app to be done when provision and deployed on a device.

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
Back to Top