I got the video to show in a Webview in landscape mode..
But somehow the video doesn't cover full screen. There is a white part at the bottom of the video which is a bit annoying..
I've tried using
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setLoadWithOverviewMode(true);
But they don't seem to fix it.
How do I make the video that played in a WebView cover the entire device screen?
if your video is live stream you don't need webview !
I prefer using Vitamio Library to stream and show inside your app!
If you want to perform HLT (HTTP Live Stream) on Android 2.1 and higher you may use the vitamio library.
Site at: (http://www.vitamio.org/).
Here is code example: The main layout:
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="2px" android:paddingRight="2px"
android:paddingTop="2px" android:paddingBottom="2px"
android:layout_width="fill_parent" android:orientation="vertical">
<io.vov.vitamio.widget.VideoView
android:layout_height="fill_parent"
android:layout_width="fill_parent" android:id="#+id/VideoView">
</io.vov.vitamio.widget.VideoView>
</LinearLayout>
the Class:
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class LiveStrimingTestActivity extends Activity{
VideoView videoView;
private void test_2(){
String httpLiveUrl = "http://aj.lsops.net/live/aljazeer_en_high.sdp/playlist.m3u8";
videoView = (VideoView) findViewById(R.id.VideoView);
videoView.setVideoURI(Uri.parse(httpLiveUrl));
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
test_2();
}
}
Related
Goal
To create a reduced TvView that displays on top of a WebView.
This is specifically for live TV.
(I've seen numerous solutions that address streaming content, but this is intended for video that's delivered through the coaxial cable.)
Where I'm At Now
The WebView portion works fine, and I've learned that a RelativeLayout is required in order to layer views.
Also, TvView doesn't seem to be recognized, so I'm guessing that I'll probably need to use a SurfaceView instead.
activity_main.xml
MainActivity.java
Questions
I've seen the TvInput, example applications, but it's extremely excessive. I'm not trying to recreate the TvInput service, just leverage on existing framework.
Is it possible to simply call on the existing, TV service that's already on the Android device, and display it in a view?
If it is possible, how is it accomplished?
If it's not possible, what's the simplest method of implementing it? (repository links would be great.)
I've searched all over for answers but can't seem to find anything.
Thank you in advance for any assistance.
Code in Text Format
As requested by tung.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_browse_fragment"
android:name="com.company.app.MainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.company.app.MainActivity"
tools:deviceIds="tv"
tools:ignore="MergeRootFrame" >
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TvView
android:id="#+id/TvView"
android:layout_width="816dp"
android:layout_height="404dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp" />
</RelativeLayout >
MainActivity.java
package com.company.app;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.media.tv.TvView;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings;
public class MainActivity extends Activity {
private WebView mWebView;
private TvView mTvView;
private WebSettings mWebSettings;
#SuppressLint("SetJavaScriptEnabled")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
mWebView = new WebView(this);
mWebSettings = mWebView.getSettings();
mWebSettings.setJavaScriptEnabled(true);
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
mWebView.loadUrl("http://10.28.98.150:1000/");
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
this.setContentView(mWebView);
mTvView = new TvView(this );
mTvView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
this.setContentView(mTvView);
}
#Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
String channelUrl="content://android.media.tv/channel/"+channelNumber;
mTvView.tune(mInputId, Uri.parse(channelUrl));
input id is available in TV database(refering to which source channel is coming from).
If you pass these info to tvview it will start playing.
I'm trying to create a WebView app that shows a meteor web app using Tiago Scolari's sample.
When i load the apk in my phone i see the background changes but the log in button doesn't show.
Anyone has a clue how to make this work?
--Edit:
Adding -
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setDomStorageEnabled(true);
- shows me the log in button and gets me to the facebook log in.
After logging in using facebook i'm presented with a white screen.
Any more advice?
Some code:
main.xml (layout):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainWebView">
</WebView>
</LinearLayout>
AndroidMobileAppSample.java (java wrapper):
package tscolari.mobile_sample;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class AndroidMobileAppSampleActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setDomStorageEnabled(true);
mainWebView.setWebViewClient(new MyCustomWebViewClient());
mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mainWebView.loadUrl("http://pastime.meteor.com/");
}
private class MyCustomWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
}
}
oke I just tested it on my 2.3.4 android and yea there is no facebooklogin. Its a WebView problem. Changed the code and still the login dosent appear...
I am new to android, I have created a simple app to load a flash player into
a webview. My flash player contains a presentation which is saved in 2 folders in the
assets
folder 1 is Data
folder 2 is Player
and my player.html
The app get installed into the tablet and starts running but once the loading bar get
half way trough it, it stay like that without completing.
This is my Activity Java file
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity
{
final Activity activity = this;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
// Handle the error
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView.loadUrl("file:///android_asset/player.html");
}
}
And Here is my XML file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="HTML in WEB View"
tools:context="MainActivity" />
<WebView
android:id="#+id/webView"
android:hardwareAccelerated="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
I have the hardware accelerated as true on the manifest
Can someone please let me know where the problem could be.
My assumptions will be
Need to grant file access to the asset folder?
Do I need to put all my files in the assets folder with no subfolder?
Is Webview waiting for me to click on an invisible pop-up window allowing flash to
access the files?
Your help is very much appreciated.
The application that generated the flash files came back with an answer stating that it is not compatible with android development.
I am trying to add a video played on button click with android studio.
However, when I click the button a "sorry, this video cannot be played" message box appears on the emulator screen.
Can you help me see where I'm going wrong.
Below is the code I approached the goal with
Trialvideo.java
package android.com.trialvideo;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;
public class TrialVideoActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** // Video view: to view our video
VideoView video = (VideoView) findViewById(R.id.surface_view);
//set video path to our video(in this case man-cheetah-gazalle.3gp)
video.setVideoPath("/raw/jeewan.mp4");
video.start();
**/
final Button play =(Button)findViewById(R.id.play);
play.setOnClickListener(new OnClickListener(){
public void onClick(View V){
videoPlayer();
}
});}
public void videoPlayer(){
getWindow().setFormat(PixelFormat.TRANSLUCENT);
VideoView videoHolder = (VideoView)findViewById(R.id.surface_view);
videoHolder.setMediaController(new MediaController(this));
videoHolder.setVideoPath("/TrialVideo/raw/lic.3gp");
videoHolder.requestFocus();
videoHolder.start();
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_height="50dip"
android:text="play"
android:id="#+id/play"
android:layout_width="50dip"
>
</Button>
<VideoView android:id="#+id/surface_view"
android:layout_width="475px"
android:layout_height="440px"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_height="50dip"
android:text="play"
android:id="#+id/play"
android:layout_width="50dip"
>
</Button>
<VideoView android:id="#+id/surface_view"
android:layout_width="475px"
android:layout_height="440px"
/>
</LinearLayout>
Hi try the following code:
VideoPlaying.java
public class VideoPlaying extends Activity {
private MediaController mc;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView vd = (VideoView) findViewById(R.id.VideoView);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"+R.raw.VideoName);
mc = new MediaController(this);
vd.setMediaController(mc);
vd.requestFocus();
vd.setVideoURI(uri);
vd.start();
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">
<VideoView android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="#+id/VideoView"></VideoView>
</LinearLayout>
place the video on the raw folder and run the code. Sometimes video will not be correctly shown on the emulator, try to check it also on the actual device.
Android does not have a C: drive. You need to put the video file on the device (e.g., copy it to the device's external storage), then supply VideoView with an appropriate path to the file (e.g., using Environment.getExternalStorageDirectory()).
I am creating a ViewFlipper that flips thru WebViews: I have no problems running the app if I place the WebViews within the main.xml. Since I will be using a multiple count of Web views, I decided to break them up into separate XML files. When I do this using the include android:id="#+id/myWebView001" layout="#layout/pg001" within the ViewFlipper of the main.xml, I get an force close when the app starts.
Please look thru the following code and if you have any suggestions for this to work correctly, it will greatly appreciate it. Thnx again!!
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ViewFlipper"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<include android:id="#+id/myWebView001" layout="#layout/pg001" />
</ViewFlipper>
main.java:
package com.aero.ac4313;
import android.app.Activity;
import android.os.Bundle;
public class main extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set your content view, this will be your layout
setContentView(R.layout.main);
}
}
pg001.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myWebView001" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
Pg001.java:
package com.aero.ac4313;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class Pg001 extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set your content view, this will be your layout
setContentView(R.layout.pg001);
WebView mWebView = null;
mWebView = (WebView) findViewById(R.id.myWebView001);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/pg001.html");
}
}
The error is obviously simple. Your main activity class is null. I believe that he added Pg001.class without linking it with the main activity class. If you did add it on the manifest file then try again.