i want to play mp3 file in background using jQuery in android phoneGap, i have included cordova-2.2.0.js with jquery-1.9.0.js file .. here is my html code. what i am doing wrong while i have given all permissions in Manifest File
here is my html page
<!DOCTYPE HTML>
<html>
<head>
<title>First App</title>
</head>
<body>
<h1>Welcome to PhoneGap</h1>
<h2>Edit assets/www/index.html</h2>
<script src="cordova-2.2.0.js"></script>
<script src="jquery-1.9.0.js"></script>
<script>
$(document).ready(function(){
alert("hey");
var audio = new Audio();
audio.src = "audio.mp3";
audio.play();
});
</script>
</body>
</html>
try this link, use media instead of audio
var myaudio = new Media('/android_asset/www/audio/file.mp3');
for Your Error Attempt to call getDuration without valid media player
try this links
https://groups.google.com/forum/#!topic/phonegap/aa_2dHjy9C0
http://www.anddev.org/multimedia-problems-f28/mediaplayer-attempt-to-call-getduration-without-t51386.html
Android: attempt to call getduration without a valid mediaplayer
http://maffelu.net/phonegap-attempt-call-getduration-without-valid-mediaplayer/
i am saying to check this link bacause you have not posted the android code so try it.
Hope this will help.
Related
I am getting the following response in HTML format when try to upload file through android app using multipart,
when i tried through postman then it works fine.
Can anybody help?
<html>
<head>
<META NAME="robots" CONTENT="noindex,nofollow">
<script src="/_Incapsula_Resource?SWJIYLWA=2977d8d74f63d7f8fedbea018b7a1d05">
</script>
<script>
(function() {
var z="";var b="7472797B766172207868723B76617220743D6E6577204461746528292E67657454696D6528293B766172207374617475733D227374617274223B7661722074696D696E673D6E65772041727261792833293B77696E646F772E6F6E756E6C6F61643D66756E6374696F6E28297B74696D696E675B325D3D22723A222B286E6577204461746528292E67657454696D6528292D74293B646F63756D656E742E637265617465456C656D656E742822696D6722292E7372633D222F5F496E63617073756C615F5265736F757263653F4553324C555243543D363726743D373826643D222B656E636F6465555249436F6D706F6E656E74287374617475732B222028222B74696D696E672E6A6F696E28292B222922297D3B69662877696E646F772E584D4C4874747052657175657374297B7868723D6E657720584D4C48747470526571756573747D656C73657B7868723D6E657720416374697665584F626A65637428224D6963726F736F66742E584D4C4854545022297D7868722E6F6E726561647973746174656368616E67653D66756E6374696F6E28297B737769746368287868722E72656164795374617465297B6361736520303A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2072657175657374206E6F7420696E697469616C697A656420223B627265616B3B6361736520313A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2073657276657220636F6E6E656374696F6E2065737461626C6973686564223B627265616B3B6361736520323A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2072657175657374207265636569766564223B627265616B3B6361736520333A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2070726F63657373696E672072657175657374223B627265616B3B6361736520343A7374617475733D22636F6D706C657465223B74696D696E675B315D3D22633A222B286E6577204461746528292E67657454696D6528292D74293B6966287868722E7374617475733D3D323030297B706172656E742E6C6F636174696F6E2E72656C6F616428297D627265616B7D7D3B74696D696E675B305D3D22733A222B286E6577204461746528292E67657454696D6528292D74293B7868722E6F70656E2822474554222C222F5F496E63617073756C615F5265736F757263653F535748414E45444C3D333631333333313435333534393034343833362C31363139373036393032363035373531353530312C31383032313737373432353133323338343837392C353833323439222C66616C7365293B7868722E73656E64286E756C6C297D63617463682863297B7374617475732B3D6E6577204461746528292E67657454696D6528292D742B2220696E6361705F6578633A20222B633B646F63756D656E742E637265617465456C656D656E742822696D6722292E7372633D222F5F496E63617073756C615F5265736F757263653F4553324C555243543D363726743D373826643D222B656E636F6465555249436F6D706F6E656E74287374617475732B222028222B74696D696E672E6A6F696E28292B222922297D3B";for (var i=0;i<b.length;i+=2){z=z+parseInt(b.substring(i, i+2), 16)+",";}z = z.substring(0,z.length-1); eval(eval('String.fromCharCode('+z+')'));})();
</script></head>
<body>
<iframe style="display:none;visibility:hidden;" src="//content.incapsula.com/jsTest.html" id="gaIframe"></iframe>
incapsula(web Security) is blocking you.
I’m trying to play a simple .MP4 via the MACDONST plugin, but get an error reading “Can’t play this video” as soon as the video player is displayed. I can play the video file in the Android standalone video player, and I can call a Youtube video via the plugin. Many thanks for your help! Here's my page code:
<!DOCTYPE html>
<html>
<head>
<title>InAppBrowser.addEventListener Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
<script type="text/javascript" charset="utf-8" src="video.js"></script>
<script type="text/javascript">
//app.initialize();
function init()
{
document.addEventListener("deviceready", console.log('ready'), true);
}
function playVideo(vidUrl) {
//alert("Starting Vid Script");
window.plugins.videoPlayer.play(vidUrl);
}
</script>
</head>
<body onload="javascript:init()">
Play Stream<br>
Play File<br>
Play File from SD<br>
</div>
</body>
</html>
First you create directory in your www location directory I named videos.
then put your stigma.mp4 file into the videos directry then call your path like bellow mentioned
Play File
Note: your video file dose not contain any special character like (, & - & _ etc..) only file file extention .mp4
I am loading html page in asset folder to android webview, the html pages has video. But video not playing, Here i share the code.
<!doctype html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" charset="utf-8" src="video.js"></script>
<script>
function en(){
video1.play();
}
</script>
</head>
<body>
<div id="t2" width ="1024" height="768" style="background- image:url(images/L6_P007.jpg); background-repeat:no-repeat;">
<video id="video1" width="1024" height="768" poster="images/L6_P007.jpg" controls autoplay onended="en();" >
<source src="videos/L6_P007.mp4" type="video/mp4">
<source src="videos/L6_P007.ogv" type="video/ogg">
<source src="videos/L6_P007.webm" type="video/webm">
</video>
</div>
</body>
</html>
This is my java code
WebView webview = (WebView) findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
webview.loadUrl("file:///android_asset/videosamp/videosamp.html");
this issue is discussed many times on SO. check the answers to similar question here
get the VideoPlayer Plugin for android here.
The video player allows you to display videos from your PhoneGap application.
This command fires an Intent to have your devices video player show the video.
Adding the Plugin to your project
Using this plugin requires Android PhoneGap.
To install the plugin, move www/video to your project's www folder and include a reference to it in your html file after phonegap.js.
Create a directory within your project called "src/com/phonegap/plugins/video" and move VideoPlayer.java into it.
In your res/xml/plugins.xml file add the following line:
<plugin name="VideoPlayer" value="com.phonegap.plugins.video.VideoPlayer"/>
Using the plugin
The plugin creates the object window.plugins.videoPlayer. To use, call the play() method:
/**
* Display an intent to play the video.
*
* #param url The url to play
*/
play(url)
Sample use:
window.plugins.videoPlayer.play("http://path.to.my/video.mp4");
window.plugins.videoPlayer.play("file:///path/to/my/video.mp4");
window.plugins.videoPlayer.play("file:///android_asset/www/path/to/my/video.mp4");
window.plugins.videoPlayer.play("https://www.youtube.com/watch?v=en_sVVjWFKk");
Note: When playing video from the assets folder, the video is first copied to internal storage with MODE_WORLD_READABLE.
I am loading an HTML file from my assets folder into a WebView using loadUrl(). The HTML file references a JW Player swf embedded alongside it in the assets folder.
I want JW Player to play a remote URL. Sadly, it will not.
If I load the SWF remotely from another server (instead of using the SWF in my assets folder) I can access external URL's. In this case, the external URL is an RTMP stream. For example:
<!DOCTYPE html>
<html lang='en'>
<head><meta charset='utf-8'>
</head>
<body style='margin:0; pading:0;background-color: #000000;'>
<script type='text/javascript' src='http://developer.longtailvideo.com/svn/trunk/fl5/jwplayer.min.js'></script>
<div id='mediaspace'>This text will be replaced</div>
<script type='text/javascript'>
jwplayer('mediaspace').setup({
'flashplayer': 'http://developer.longtailvideo.com/svn/trunk/fl5/player.swf',
'file': 'testvid.mp4',
'streamer': 'rtmp://b27i9s9t3.rtmphost.com/AndroidMedia',
'controlbar': 'bottom',
'width': '800',
'height': '450'
});
</script>
</body>
...works
<!DOCTYPE html>
<html lang='en'>
<head><meta charset='utf-8'>
</head>
<body style='margin:0; pading:0;background-color: #000000;'>
<script type='text/javascript' src='file:///android_asset/jwplayer.min.js'></script>
<div id='mediaspace'>This text will be replaced</div>
<script type='text/javascript'>
jwplayer('mediaspace').setup({
'flashplayer': 'file:///android_asset/player.swf',
'file': 'testvid.mp4',
'streamer': 'rtmp://b27i9s9t3.rtmphost.com/AndroidMedia',
'controlbar': 'bottom',
'width': '800',
'height': '450'
});
</script>
</body>
...does not work. JW Player loads - but once the play button is hit it flashes a quick "connection unavailable: error #2028" and then spins the ajax spinner forever.
I'm assuming this is a general issue with all SWF's loaded from the assets folder into a web view and is not specific to JW Player.
Any ideas?
Anyone know for sure if playing local mp3 file using HTML5 is possible or not in Android?
Playing mp3 files from url's works fine, but not when embedded in the app. Been searching for definitive answer.
Thanks for any help
<html>
<head>
<title>Audio Player</title>
</head>
<body>
<br /> <br />
<audio id="player" autoplay loop controls="controls">
<source src="bassscales.mp3" />
</audio>
<br /> <br />
<div>
<button style="width:85;height:75" button onclick="document.getElementById('player').play()">Play</button>
<button style="width:85;height:75" button onclick="document.getElementById('player').pause()">Pause</button>
<button style="width:85;height:75" button onclick="document.getElementById('player').pause(); document.getElementById('player').currentTime = 0;">Stop</button>
</div>
</body>
</html>
I had the same problem with HTML5 and <video> tag, video playing fine if called programatically from file system, but when called from the tag, didn't work,
the way I solved it is having a javascript function in the HTML call the android system, in your case for playing an mp3
Android JavaScriptInterface tutorial
also check my question in the same subject
note that you need to place in the correct folder the mp3 [sorry don't remember in which folder, make a search and find it easy]
so first do a hello world javascript calling a log or basic function in android,
then make the javascript call the play function,
good luck
ps.
playing mp3 from assets folder example
and calling Android methods with javascript
jsInterface example
Does this look correct for the HTML file?
<body>
<video id="video" controls height="270" src="http://dl.dropbox.com/u/39276137/intro1girl.mp4" width="480">
</video>
<script type="text/javascript">
var video = document.getElementById('video');
video.addEventListener('click',function(){
MyAndroid.video.play();
},false);
</script>
then don't know what to put in the JavaScriptInterface.java class...thanks for all the help :)