简体   繁体   中英

how to play mp3 file in phonegap using javascript

I am developing one phoneGap application. And I used the below code for application but i got the error.

Below is my folder structure of phonegap

App
--.svn
--hooks
--platforms
--plugins
--www
-- --index.html
-- --Song
-- -- --Rang Laal.mp3

I am using below code for play the song:

<script>
    function playAudio(id) {

        var url = audioElement.getAttribute('src');
        var my_media = new Media('Song/Rang Laal.mp3',
                // success callback
                 function () { console.log("playAudio():Audio Success"); },
                // error callback
                 function (err) { console.log("playAudio():Audio Error: " + err); }
        );
        // Play audio
        my_media.play();
    }
</script>

Below is the error that i am getting

Error: SyntaxError: missing ; before statement       
          phonegap-1.4.1.js (line 671)

Actually my all .mp3 file will store in server. I have to just play from mobile. please suggest a way for that. using url we can able to play? or some plugin available in phonegap?

Awaiting for response.

i tried this plugin cordova-plugin-media which worked perfectly. Check that link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM