I am using Media.getDuration() function to get duration of an audio file but I am always getting -1 as response.
This works fine if I build using build.phonegap.com
But whenever I build using cli I then getDuration does not work.
Following are simple steps to reproduce this issue:
CLI:
cordova start my_project
cordova plugin add cordova-plugin-media
cordova platform add android
cordova build android
www/index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Media Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
function deviceready()
{
var my_media = new Media('http://web.com/mp3');
my_media.play();
console.log(my_media.getDuration()); // this will produce -1
}
</script>
</head>
<body>
</body>
</html>
Alright I got solution. I was using using old version of media plugin by default ( i think 2.0 ) I used removed old plugin with following command:
Then I installed latest version of same plugin by using following command:
And then I buit it again and it worked like charm.
Thanks