I’m trying to display a page of embed YouTube videos. I got the code from YouTube website. The page gets displayed correctly when I load it up in the browser but on my embedded web page the YouTube videos do not show the first frame. Its just a black box with the YouTube logo on the bottom. If you click on it, it does play the video. I tread to enable java script, still did not work.
public class cVideos extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videos);
WebView mWeb=(WebView) findViewById(R.id.webvideo);
mWeb.getSettings().setJavaScriptEnabled(true);
mWeb.getSettings().setJavaScriptEnabled(true);
// mWeb.loadUrl("http://www.besttechsolutions.biz/projects/bigbiz/mobvideo.php");
mWeb.loadUrl("http://www.besttechsolutions.biz/projects/bigbiz/videored.php");
}
}
Try embedding &autoplay=1 in the src attribute of the iframe tag in the page source.
Even so, autoplay will not work on Android 2.1 devices, as they cannot support HTML5 video in the browser.
Related
I play a video in a videoview from an URL...everything works fine and even the video plays
But the only problem is that the video takes almost 10 seconds to start playing which might be kind of annoying to the user
I have tried different URLs and its the same, the videos are 360p and 6sec long
Is it the default media player that is slow?
I have the stack overflow but could not find a suitable answer and ever searched for various 3 rd party videos libraries but could not find one
Even tried google's exoplayer library but the documentation is not that good in my view
Is there any solution how to overcome this problem?
my code
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String videeourl = "http://techslides.com/demos/sample-videos/small.3gp";
VideoView videoView = (FastVideoView)findViewById(R.id.video);
videoView.setMediaController(new MediaController(this));
videoView.setVideoPath(videeourl);
videoView.start();
}
}
Consider using Exoplayer. You can find the open source project here:
https://github.com/google/ExoPlayer
It uses Dynamic Adaptive Streaming over HTTP (DASH),breaks long content into HTTP segments.
You can follow this tutorial step-by-step to integrate ExoPlayer (ExoPlayer is the video player running in the Android YouTube app.) to your app, it's not that complicated as you thought.
https://codelabs.developers.google.com/codelabs/exoplayer-intro/index.html#0
By the way, there are a lot of good assignments in Google CodeLabs, you should check it out.
Trying to get a simple video clip playing in a loop. I got the video to play just fine. However, there are two problems I'm having.
If the user clicks the Home button, effectively hiding the app. Then they go back to it, the video is gone and doesn't reload.
Everything as far as initializing the video only takes place in the typical onCreate for the view that holds it. Where should I be calling the video from to start it to ensure that it always actually starts?
I can only get the device to find the video when pulling it from the web. I see in the logs that when I try to reference the clip from the RAW folder, it cannot find it.
VideoView myVideoView = (VideoView)findViewById(R.id.lighterView);
myVideoView.setVideoURI(Uri.parse("android.resource://com.android.AndroidVideoPlayer/"+R.raw.[videoclip]));
myVideoView.requestFocus();
myVideoView.start();
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer myVideoView) {
myVideoView.setLooping(true);
}
});
The above chunk of code works fine if I use a URL to my website. But locally, it cannot find the clip.
Instead of just load/play video in onStart() method I suggest you to look at some well written code about VideoView, because the best way to connect your video to your interface is manage your VideoView(that implements surfaceView) callBack.
You can find a good example at the following link;)
http://alvinalexander.com/java/jwarehouse/android/core/java/android/widget/VideoView.java.shtml
i am trying to load a webpage on a web view where the page has a video in it. i am able to load the web page on the web view but the video is not playing and the audio is heard. this is the link i m loading to a web view.
http://html5videoformatconverter.com/html5-video-tag-example.html
and all i m doing is
public class VideoActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView mWebView = (WebView) findViewById(R.id.wvVideo);
mWebView.setWebChromeClient(chromeClient);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl("http://html5videoformatconverter.com/html5-video-tag-example.html");
}
private WebChromeClient chromeClient = new WebChromeClient(){
#Override
public void onShowCustomView(View view, CustomViewCallback callback) {
// TODO Auto-generated method stub
super.onShowCustomView(view, callback);
if(view instanceof FrameLayout){
FrameLayout frame = (FrameLayout)view;
if(frame.getFocusedChild()instanceof VideoView){
VideoView video = (VideoView)frame.getFocusedChild();
frame.removeView(video);
video.start();
}
}
}
};
}
pls help me modify my code. thanks
Android Browser and WebView has many known problems playing HTML5 <video> videos.
Android webview cannot render youtube video embedded via iframe
Unless you can target Android 4.0 or good modern firmwars, the current workaround is to have a thumbnail image link to a video and then this link opens the video in the native Android video player.
For more information with HTML5 video problems on Android please feel free to search stackoverflow.com.
This worked for me, problem was to do with file permissions on the locally stored video. Hope it helps!
<video width="365" height="200" src="/mnt/SDcard/media/video/abc.mp4" controls autobuffer></video>
As #Mikko says, this is a tricky area.
One thing to check is that you have hardware acceleration enabled. I encounter the exact same symptoms the OP describes when leaving it turned off.
You can enable it at the application or at the activity level:
<application
android:icon="#drawable/icon_72"
android:logo="#drawable/icon_menu_72"
android:label="#string/app_name"
android:hardwareAccelerated="true"
>
OR
<activity
android:name=".MyActivity"
android:hardwareAccelerated="true"
>
When I encountered this problem it was due to the compression type. For android I had to use base profile compression rather than high profile compression. ffmpeg compatibility has a description.
I answered a similar question here.
I was converting my mobile website with youtube embeds into android app....this project helped me get rid of getting the video to fullscreen in webview. All my problems were solved. You can get something from here.
https://code.google.com/p/html5webview/
I have a webview in my application which upon launch displays an html page. The page has a hyperlink which on click is supposed to display a video.
When i run the application and click on the video hyperlink link , nothing happens. But if i load the same page in android browser, then it launches a default video player and everything works fine.
I debugged it furthers by putting a log statement in shouldOverrideUrlLoading method and noticed that, when the hyperlink is clicked it gets redirected to another link and then to another link (final video streaming url).
My question is : why would the link work perfectly in default android browser and not through a webview.
Thanks
What is happening is when you click the hyperlink, that link probably has some popups inside of it. You need to define the onCreateWindow function in your webview's WebChromeClient. This handles how calls to open new windows or popups are handled.
public boolean onCreateWindow (WebView view, boolean dialog, boolean userGesture, Message resultMsg) {
((WebView.WebViewTransport) resultMsg.obj).setWebView(myWebView);
resultMsg.sendToTarget();
return true;
}
After declaring your WebView you should set javascript enabled, then your WebView will work as a browser.
For example:
WebView mwebview = new WebView(this);
setContentView(mwebview);
mwebview.getSettings().setJavaScriptEnabled(true);
or
mwebview.getSettings().setPluginState(PluginState.ON); // this is for newer API's
Basically, do not expect your embedded WebView works the same as Android default Browser. The default Browser is built on the same WebView, but there are lots a customization. (Especially around the no-standard uri, HTML5 stuff)
I followed code from here: WebView and HTML5 <video>, and I put the video link to a video tag, and I got the Video playing in my own version of WebView. The behavior is a little different from the default Browser. Given more time, we could figure that out by looking at its code, but anyways ...
There is one HTML page, streaming a music file and It's working on window but i need to run this html file on android.
also i need to control all the feature of music by javascript function e.g. play,pause,stop, volume up & down.
Can someone give me any idea?
Note : i am new to android but good hand in java. Just going through android tutorial and i came to know this feature can be done using webview. is it ?
Its not clear from the post if its a requirement that you have to play it on a html page or you just want to play the .mp3 file linked from some online page.
However, You can look at this Streaming Audio tutorial as an initial reference. The MediaPlayer API would be your goto place in android for anything to do with Audio/ Video. WebView is mainly for embedding a browser view within your android App.
Here is an example quite close to the thing you're going to do...
public class MyJSInterface{
private MediaPlayer mp = new MediaPlayer();
....
public void play(String url){
this.mp.setDataSource(url);
this.mp.prepare();
this.mp.start();
// AlterDialog etc.
}
public void stop(){
this.mp.stop();
}
....
}
HTML from your website:
function _play(url){
window.myappname.play(url);
}
function _stop(url){
window.myappname.stop();
}
thing you may need
Android Media