I want to know, how can I play mp3 audio file on Andoid using Phonegap Build?
I put my mp3 file in a folder, then using the tag to put it on my page but it is not playing.
Help!
I put my mp3 file in a folder, then using the tag to put it on my page but it is not playing.
<audio controls loop>
<source src="demo.mp3" type="audio/mpeg">
</audio>
Help!
- 57 Posts
- 0 Reply Likes
Posted 6 years ago
- 57 Posts
- 0 Reply Likes
I have a good news, well not totally a best one. It is working.I missed the cordova.js file. The documentation does not mention it.
I managed to play it. Yes, it is playing now. However, pause and stop are not working. Here are my full codes:
Why the pause and stop are not working?
I managed to play it. Yes, it is playing now. However, pause and stop are not working. Here are my full codes:
<script>
var my_media = new Media(src, onSuccess, onError);
// Play audio
function playAudio(url) {
var my_media = new Media(url,
function () {
console.log("playAudio():Audio Success");
},
function (err) {
console.log("playAudio():Audio Error: " + err);
}
);
my_media.play();
}
// Pause audio
function pauseAudio(url) {
var my_media = new Media(url,
function() {
console.log("pauseAudio():Audio Success");
},
function(err) {
console.log("pauseAudio():Audio Error: "+err);
}
);
my_media.pause();
}
// Stop audio
function stopAudio(url) {
var my_media = new Media(url,
function() {
console.log("stopAudio():Audio Success");
},
function(err) {
console.log("stopAudio():Audio Error: "+err);
}
);
my_media.stop();
}
</script>
<a onclick="playAudio('/android_asset/www/demo.mp3');">Lecture</a>
<a onclick="pauseAudio('/android_asset/www/demo.mp3');">Pause</a>
<a onclick="stopAudio('/android_asset/www/demo.mp3');">Stop</a>
Why the pause and stop are not working?
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
Because you are instantiating a new object in every function, instead of using the current Media object's pause and stop methods.
- 57 Posts
- 0 Reply Likes
So, I have to chnage only for the pause and stop, right? In short, it will be like this?
function pauseAudio() {
myMedia.pause();
}
function stopAudio() {
myMedia.stop();
}
John Weidner, Champion
- 435 Posts
- 80 Reply Likes
I'd suggest going through some javascript tutorials before trying to continue with PhoneGap.
- 57 Posts
- 0 Reply Likes
I am just following what is included on the documentations. I am not at fault if Phonegap's documentations are not well detailed. Documentations are made to follow and for beginners if I am not mistaken.
I have successfully tried to play this, I am getting issues only on this pause and stop things. I came here for help, and my question can also help many others.
I have successfully tried to play this, I am getting issues only on this pause and stop things. I came here for help, and my question can also help many others.
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
Well, yes, I agree that the PGB documentation is not of prize winning quality. But even if it was, it would still require some basic knowledge of OO, HTML and JavaScript.
In this thread, you have shown that you can copy and paste JavaScript code, but have difficulties applying examples in your own code and understanding sample code.
The problem is, apparently, not PGB, but JavaScript in general. That's why John suggested that as a good starting point, before attempting to apply insufficient knowledge to imperfect documentation. I agree with him.
In this thread, you have shown that you can copy and paste JavaScript code, but have difficulties applying examples in your own code and understanding sample code.
The problem is, apparently, not PGB, but JavaScript in general. That's why John suggested that as a good starting point, before attempting to apply insufficient knowledge to imperfect documentation. I agree with him.
John Weidner, Champion
- 435 Posts
- 80 Reply Likes
Have you figured out how to see the output from javascript console.log statements when you run this app on your device?
- 57 Posts
- 0 Reply Likes
Well, I have successfully made it play, pause and stop by following this tutorial:
http://docs.phonegap.com/en/3.3.0/cor...
However, I have modified it in my own way which is good now. Anyway, after spending hours on this, now it is working perfectly.
Thank you to each of you for assisting me.
http://docs.phonegap.com/en/3.3.0/cor...
However, I have modified it in my own way which is good now. Anyway, after spending hours on this, now it is working perfectly.
Thank you to each of you for assisting me.
John Weidner, Champion
- 435 Posts
- 80 Reply Likes
Congratulations! Please post your code here to help out the next person that is trying to do the same thing.
- 57 Posts
- 0 Reply Likes
The codes are the same like on the documentation I posted above. Except, I changed my buttons, removed the pause and duration, that's all.
The only issue is, the audio starts playing by itself while the page loads. A bug in the documentation it seems!
The only issue is, the audio starts playing by itself while the page loads. A bug in the documentation it seems!
- 57 Posts
- 0 Reply Likes
i just removed that device ready function where it is calling the playAudio, this is why the audio starts playing automatically.
Now, everything is fine and everything is working well.
Again, thank you to each of you!
Now, everything is fine and everything is working well.
Again, thank you to each of you!
This conversation is no longer open for comments or replies.
This conversation is no longer open for comments or replies.
Related Categories
-
PhoneGap Build
- 15111 Conversations
- 275 Followers


