Play a Sound

19 posts, 0 answers
  1. Kevin
    Kevin avatar
    5 posts
    Member since:
    Jul 2013

    Posted 04 Aug 2013 Link to this post

    How do  i play a mp3 or ogg file.
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 06 Aug 2013 Link to this post

    Hi Kevin,

    You could play an audio file using the Cordova Media API. You can clone and examine our media sample to get started.

    Regards,
    Steve
    Telerik

    Do you enjoy Icenium? Vote for it as your favorite new product here (use short code H048S).
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  3. Jay
    Jay avatar
    1 posts
    Member since:
    Aug 2013

    Posted 22 Aug 2013 Link to this post

    The media player sample doesn't seem to play the sound for me in the Android simulator. It works in the iPhone simulator though.
  4. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 26 Aug 2013 Link to this post

    Hi Jay,

    Thanks for pointing this out - it is a bug in the simulator and I've logged it for fixing. It would work just fine if you deploy it on an actual Android device.

    Your Telerik points have been updated for your involvement.

    Regards,
    Steve
    Telerik

    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  5. David
    David avatar
    6 posts
    Member since:
    Jul 2013

    Posted 08 Oct 2013 Link to this post

    I get the sound to play on Iphone5 and Android but on Iphone 4 it throws and error Cannot use audio file from resource '/var/mobile/Applications/XXXXXXXX/IceniumIon.app/www/audio/Click01.m4a'

    Any help how should I define the route?

    I have the following code.

    src=getPhoneGapPath() +"audio/Click01.m4a";
    my_media = new Media(src, onSuccess, onError);

    Thanks
  6. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 09 Oct 2013 Link to this post

    Hello Camilo,

    The specific device model should be irrelevant, most likely the iOS version is different. What OS versions are the iPhone 5 and iPhone 4 running? Also can you reproduce this problem if you deploy your app to the actual device directly (and not by using Icenium Ion)?

    If you still need help, let us know the name of your app and the iOS version of the problematic device and we would investigate.

    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.
  7. Andi
    Andi avatar
    2 posts
    Member since:
    Oct 2013

    Posted 13 Oct 2013 Link to this post

    As described above it plays the sound in the Simulator for IPhones and not for Androids.


    I now tried it on my Android and it doesn't play them there as well.
    Scanning the QR and installing the App should actually deploy it? Or do i have to do s.th. else? Is it required to put the file in a special folder? My path is "lessons/lesson-1.mp3".
  8. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 14 Oct 2013 Link to this post

    Hello Andi,

    In case you want to play local files you should refer them with a specific Android prefix:

    "/android_asset/www/lessons/lesson-1.mp3"

    You can find more information about this in the following blog post: Using the Media Class in PhoneGap.

    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.
  9. Andi
    Andi avatar
    2 posts
    Member since:
    Oct 2013

    Posted 14 Oct 2013 Link to this post

    Hi Steve,

    thanks for the quick reply. Basically what I want to do is to build a lecture app. The app downloads the sound files for a lecture and plays them. If possible the user should not be able to access the sound files from his computer because it will be subscription based.

    I found that with the www folder before but I didn't quite understand three things:

    1) How can I make it cross platform with that aproach? 

    2) Adding the folders /android_asset/www/ to my workspace doesn't help. So where do I access them on Icenium Graphite? 

    3) Do I get it right, that there is one asset folder for each app (http://stackoverflow.com/questions/5030448/android-how-to-find-the-absolute-path-of-the-assets-folder)?  Can I define if it is accessible?
  10. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 18 Oct 2013 Link to this post

    Hello Andi,

    I think you misunderstood my previous reply. You are not supposed to create such folders in your project, those folders are already there on Android and your app is being placed in it. You can easily verify that by evaluating window.location.pathname which would return the path to your active page.

    To make this cross-platform, you can use Cordova's device.platform to set the path for Android and iOS separately, something like:

    if (device.platform == "Android") {
        src = new Media("/android_asset/www/lessons/lesson-1.mp3");
    } else {
        src = new Media("lesson-1.mp3");
    }

    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.
  11. Andy
    Andy avatar
    2 posts
    Member since:
    Dec 2013

    Posted 16 Jan 2014 Link to this post

    Hi,

    When running in emulator I have two errors displayed and no sound. I'm using Icenium Mist with Google Chrome.

    The errors are:
    code: undefined
    message: undefined

    Best,
    Andy
  12. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 20 Jan 2014 Link to this post

    Hi Andy,

    Are you by any chance using the Cordova File API in your project? If that is the case, make sure the File core plugin is enabled in the project properties.

    If that is not it, please use the Debugger tools of the Icenium simulator, the Console tab should contain exact error and where it occurs.

    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.
  13. Thomas
    Thomas avatar
    1 posts
    Member since:
    May 2014

    Posted 26 May 2014 in reply to Steve Link to this post

    Hi Steve,

    I'm not able to play local audio files on iOS PhoneGap. To get the path to the file I use this method:

    var getPhoneGapPath = function() {
       var path = window.location.pathname;
       var phoneGapPath = path.substring(0, path.lastIndexOf('/') + 1);
       var devicePlatform = device.platform;
          if(devicePlatform == "iOS"){
          return 'file://' + phoneGapPath;
            }
            else if(devicePlatform == "Android" || devicePlatform == 'android'){
        return phoneGapPath;
            }
    };

    But you wrote in one of your posts that it is possible to use
    if (device.platform == "Android") {
        src = new Media("/android_asset/www/lessons/lesson-1.mp3");
    } else {
        src = new Media("lesson-1.mp3");
    }

    Does this mean that I do not need the path when playing from iOS? Or if I do, why does my code not working? Thanks :D
  14. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 27 May 2014 Link to this post

    Hello Thomas,

    If you're using the PhoneGap Media plugin, you don't really need to provide the absolute path to the media file in iOS. A relative path suffices as demonstrated in the Media Plugin docs. You can find a sample solution demonstrating how to play an audio file in an iOS device attached in the How to Play a Small Sound File forum thread.

    In Android, on the other hand, you need to provide the path to the file using the specific Android prefix previously described in this thread. This means that if you need your app to run in both iOS and Android, you can use the following code:
    // Audio player
    var playAudio= function () {
        var path = "";
        var devicePlatform = device.platform;
        if (devicePlatform === "iOS") {
            path = "media/SleepAway.mp3";
        } else if (devicePlatform === "Android" || devicePlatform === 'android') {
            path = "/android_asset/www/media/SleepAway.mp3";
        }
        media = new Media(path, onSuccess, onError);
        media.play({numberOfLoops: 1});          
    };

    However, please note that the above code snippet takes advantage of the Device core plug-in and you need to make sure it is enabled in the AppBuilder project before using it to check the platform of the device.

    I hope this information helps.

    Regards,
    Tina Stancheva
    Telerik
     

    Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!

     
  15. SenthilMurugan
    SenthilMurugan avatar
    1 posts
    Member since:
    Jul 2014

    Posted 14 Jul 2014 in reply to Tina Stancheva Link to this post

    I am using media plugin to play local audio files (inside /www folder). This perfectly works in android but in iOS the error "Cannot play the audio file from resource…." is coming.
    Please check the below screenshot. How should i solve this to play local audio files.
    function getPhoneGapPath() {
    'use strict';
    var path = window.location.pathname;
    var phoneGapPath = path.substring(0, path.lastIndexOf('/') + 1);
    return phoneGapPath;
    };
    my_media = new Media(getPhoneGapPath() +'button-click.wav', onSuccess, onError);
  16. Don
    Don avatar
    66 posts
    Member since:
    Jun 2012

    Posted 15 Jul 2014 Link to this post

    This is just an FYI for those of you using Media to play sounds.

    My app used to Media and it would play sounds ok, for the most part.  However, if I started to play multiple sounds in succession, the app would start to lag, especially on older devices.  Then, I stumbled upon this article:

    http://www.tricedesigns.com/2012/01/25/low-latency-polyphonic-audio-in-phonegap/

    and this related plugin:

    https://github.com/triceam/LowLatencyAudio

    I installed the plugin and used it to play sounds and then most of my lag issues were gone.  One thing to note is that though everything seems to play and run fine, I see some strange messages in logcat related to the sounds.  But, again, everything seems to run fine and I don't see errors when debugging the app itself.

    I hope this helps someone.

  17. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Jul 2014 Link to this post

    Hi guys,

    @Senthil - I tried to reproduce the issue you reported but to no avail. I used the code snippet you posted and I prepared a sample app. I was able to successfully play the sound on a few different iOS devices. I attached the sample for reference. Please give it a try on your side and let me know if there is anything I am missing.

    @Don - Thank you for sharing your experience with the LowLatencyAudio plugin. I am sure the community will appreciate the feedback.

    Regards,
    Tina Stancheva
    Telerik
     

    Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!

     
  18. vlas
    vlas avatar
    2 posts
    Member since:
    Sep 2014

    Posted 08 Mar Link to this post

    Hi, I am trying to use the Low Latency plugin in Kendo Mobile but plugin is giving me error like "preloadFX" is undefined, so i need help.?

  19. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 11 Mar Link to this post

    Hello Vlas,

    I suppose you're using a custom plugin for low latency audio. In that case would you please make sure you've followed these instructions to import the plugin in your app. Also please keep in mind that:
    • In order to access the custom plugin API you need to wait for the Cordova devceready event to fire
    • Test the plugin behavior directly on a device as neither the Device Simulator nor the AppBuilder companion apps support custom plugins

    If those suggestions don't help, you can submit a support ticket with a sample app replicating the issue and our support engineers can have a look at it and suggest solutions.

    Regards,
    Tina Stancheva
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top