This is a migrated thread and some comments may be shown as answers.

Play a Sound

18 Answers 256 Views
AppBuilder Windows client
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kevin
Top achievements
Rank 1
Kevin asked on 04 Aug 2013, 11:09 AM
How do  i play a mp3 or ogg file.

18 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 06 Aug 2013, 01:49 PM
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.
0
Jay
Top achievements
Rank 1
answered on 22 Aug 2013, 05:51 PM
The media player sample doesn't seem to play the sound for me in the Android simulator. It works in the iPhone simulator though.
0
Steve
Telerik team
answered on 26 Aug 2013, 03:15 PM
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.
0
David
Top achievements
Rank 1
answered on 09 Oct 2013, 03:13 AM
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
0
Steve
Telerik team
answered on 09 Oct 2013, 12:39 PM
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.
0
Andi
Top achievements
Rank 1
answered on 13 Oct 2013, 07:33 PM
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".
0
Steve
Telerik team
answered on 14 Oct 2013, 07:53 AM
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.
0
Andi
Top achievements
Rank 1
answered on 14 Oct 2013, 08:45 AM
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?
0
Steve
Telerik team
answered on 18 Oct 2013, 07:35 AM
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.
0
Andy
Top achievements
Rank 1
answered on 17 Jan 2014, 01:54 AM
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
0
Steve
Telerik team
answered on 20 Jan 2014, 05:01 PM
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.
0
Thomas
Top achievements
Rank 1
answered on 26 May 2014, 11:18 AM
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
0
Tina Stancheva
Telerik team
answered on 27 May 2014, 01:51 PM
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!

 
0
SenthilMurugan
Top achievements
Rank 1
answered on 14 Jul 2014, 09:53 AM
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);
0
Don
Top achievements
Rank 1
answered on 16 Jul 2014, 01:54 AM
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.

0
Tina Stancheva
Telerik team
answered on 17 Jul 2014, 10:09 AM
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!

 
0
vlas
Top achievements
Rank 1
answered on 08 Mar 2016, 06:57 AM

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.?

0
Tina Stancheva
Telerik team
answered on 11 Mar 2016, 10:09 AM
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.

 
Tags
AppBuilder Windows client
Asked by
Kevin
Top achievements
Rank 1
Answers by
Steve
Telerik team
Jay
Top achievements
Rank 1
David
Top achievements
Rank 1
Andi
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Thomas
Top achievements
Rank 1
Tina Stancheva
Telerik team
SenthilMurugan
Top achievements
Rank 1
Don
Top achievements
Rank 1
vlas
Top achievements
Rank 1
Share this question
or