Reputation: 787
I am using jacvascript to play the mp3 file.
<html>
<body>
<input type="button" onclick="playmusic();" value="click me">
<script type="text/javascript">
function playmusic(){
var audio = new Audio('flipit.mp3');
audio.play();
}
</script>
</body>
</html>
Its works fine. But, in my phonegap application the mp3 file does not work.
Upvotes: 0
Views: 579
Reputation:
Try something like this hope will work for you.
<html>
<head>
<script type="text/javascript">
function playmusic()
{
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'filename.mp3');
audioElement.setAttribute('autoplay', 'autoplay');
}
</script>
</head>
<body>
<input type="button" onclick="playmusic();" value="click me">
</body>
</html>
Upvotes: 2
Reputation:
Use media instead of audio.
var myaudio = new Media('flipit.mp3');
Try that.
EG:
function playStream() {
var myaudio = new Media('flipit.mp3');
myaudio.play();
}
update based on your comment
You need to add the media plugin to your project -
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media.git
Run that above command within the project's directory and you should be set.
Upvotes: 0