Software Archive
Read-only legacy content
17061 Discussions

The simplist way to play audio

Isaiah_L_
Beginner
830 Views

I have spent the last 7 hours trying to figure this one and nothing seems to work.

I'm trying to get some audio bg music playing and nothing works. I have used wav, ogg and mp3. I have also used the cordova media plugin, the intelxdk audio and Player plugins and nothing works. The only think that seems to work in html5 audio tags but I don't want that because it continues to play when the app is minimized.

Can someone please please post the simplest way to get music play when the app loads.
This is the last thing that I tried. music is in the same folder as index.html, using cli 5.1.1

function onAppReady() {
  if( navigator.splashscreen && navigator.splashscreen.hide ) {
    navigator.splashscreen.hide() ;
    var media = new Media("music.ogg");
    media.play();
  }
}

0 Kudos
5 Replies
Isaiah_L_
Beginner
830 Views

I might add that I compiled the sample audio player and it works but I cant make heads or tail of the code, I wish that they would make the code simple and easy to understand. My JS skills are very basic and when I see all kinds of crazy coding my brain just turns off. So if you are gonna post some help can you please make is simple and strait forward? Thanks!

0 Kudos
PaulF_IntelCorp
Employee
830 Views

Try using the "hello-cordova" sample to see how to use the media plugin to play audio. It has many comments and is structured to make the code easier to understand.

0 Kudos
Isaiah_L_
Beginner
830 Views

Yeah I tried that to no avail. i just don't understand it. My JS is VERY basic. Can anyone please tell me why that code I have there in my first post isn't working? Isn't that the basic requirements to get music playing?

0 Kudos
PaulF_IntelCorp
Employee
830 Views

Probably because the media function cannot find the file. Please see the sample I provided, it handles this. How you locate the file is a function of the platform, thus the reason it's more complex in the example.

0 Kudos
Isaiah_L_
Beginner
830 Views
Thanks.
0 Kudos
Reply