- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I was trying the cordova media plugin to play sound on intel xdk and android phone. The following code I used works fine on desktop browsers including firefox, ie and chrome and the Intel App Preview installed on my android phone. However, it doesn't work on intel xdk emulator and android phone. I also added the Media plugin in Project configuration., but it won't change anything. What I am missing in the code? Thanks a lot in advance.
<!DOCTYPE html> <html> <head> <title>Blank Hybrid App Project Template</title> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> --> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> <!-- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, minimum-scale=1, maximum-scale=2"> --> <style> /* see http://dev.w3.org/csswg/css-device-adapt/ */ @-ms-viewport { width: 100vw ; zoom: 100% ; } @viewport { width: 100vw ; zoom: 100% ; } @-ms-viewport { user-zoom: fixed ; } @viewport { user-zoom: fixed ; } </style> <script> // only work on desktop browsers rather than on android function playAudio(src) { // HTML5 Audio if (typeof Audio != "undefined") { new Audio(src).play() ; // Phonegap media } else if (typeof device != "undefined") { // Android needs the search path explicitly specified if (device.platform == 'Android') { src = '/android_asset/www/' + src; } var mediaRes = new Media(src, function onSuccess() { // release the media resource once finished playing mediaRes.release(); }, function onError(e){ console.log("error playing sound: " + JSON.stringify(e)); }); mediaRes.play(); } else { console.log("no sound API to play: " + src); } } </script> </head> <body> <!-- Main stage for rendering game scenes --> <button onclick="playAudio('asset/sound.mp3')">Play</button> <script src="intelxdk.js"></script> <!-- phantom library, needed for Intel XDK api calls --> <script src="cordova.js"></script> <!-- phantom library, needed for Cordova api calls --> <script src="xhr.js"></script> <!-- phantom library, needed for Intel XDK CORS --> <script src="js/cordova-init.js"></script> <script src="js/app.js"></script> </body> </html>
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can refer to Paul's link on how to access the sound file within the android file system. As for Intel XDK emulator, it does not support .mp3 files. Only .wav and .ogg files. Hope that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks lot for help. I'll test the above example asap.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I tested the cordova media plugin by following the above example. It works like charm on android 4.4 and the xdk emulator. Thanks a lot :-)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page