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.
Related
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.
WEBM / MP4 LOCAL files (from SD CARD) are not playing for me in the Android Chrome Browser (29.0.1457.59).
When i browse to this page in Android Chrome both the WEBM and MP4 are playing fine.
http://www.quirksmode.org/html5/tests/video.html
But if i download the 2 videos (big_buck_bunny.mp4, big_buck_bunny.webm) in the above URL in my Android Device and access them from the Chrome browser, both the videos are NOT playing for me.
I have also created an HTML page with the following VIDEO Tags. These are not working as well and i just get the BLACK Player with the controls.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
function fnOnLoad() {
var video1 = document.getElementById('vid_1');
video1.addEventListener('click', function () {
video1.play();
}, false);
var video2 = document.getElementById('vid_2');
video2.addEventListener('click', function () {
video2.play();
}, false);
}
</script>
</head>
<body style="padding: 0px; margin: 0px;" onload="fnOnLoad();">
<video id="vid_1" controls>
<source src="file:///mnt/sdcard/big_buck_bunny.mp4" type="video/mp4">
<p>Your browser does not support H.264/MP4.</p>
</video>
<br />
<br />
<video id="vid_2" controls>
<source src="file:///mnt/sdcard/big_buck_bunny.webm" type="video/webm">
<p>Your browser does not support WebM.</p>
</video>
</body>
</html>
Thanks
Seems to be fixed in the latest beta v30.0.1599.50
https://play.google.com/store/apps/details?id=com.chrome.beta&hl=en
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 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 :)