Affichage vidéo sur Android Webview. La vidéo devient noire pendant la lecture et le son se produit mais l'écran vidéo devient noir. Je travaille sur les versions Android 15+. ? Ce qui est nécessaire pour jouer à ce .. un certain appareil fonctionner très bien ..Affichage de la vidéo html5 sur Android Webview. La vidéo devient noire pendant la lecture
Code Xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.gowsample.MainActivity" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/sam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/webView1"
android:layout_below="@+id/webView1"
android:layout_marginTop="36dp"
android:text="@string/hello_world" />
Code MainActivity:
package com.example.gowsample;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
public class MainActivity extends Activity {
private WebView mWebview ;
@SuppressLint({ "NewApi", "SetJavaScriptEnabled" }) @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebview = (WebView)findViewById(R.id.webView1);
mWebview.getSettings().setMediaPlaybackRequiresUserGesture(false);
mWebview.getSettings().setJavaScriptEnabled(true);
String myvar = "";
String head = "<!DOCTYPE html><html><head><meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\" /></head>";
String summary = "<style>table{ height:100%;}td.height{height:100%;}</style><table width=100% height=100%> <tr><td class=\"height\" style=\"text-align: center; vertical-align: middle;\"><video id='my-video' controls autoplay style=\"width: 350px; height: 250px;vertical-align: middle;\"><source src='http://techslides.com/demos/sample-videos/small.mp4' type='video/mp4' /></video></td></tr></table>";
String html = head + "<body>"+summary+"</body></html>";
mWebview.loadData(html, "text/html", null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
garder l'habitude d'ajouter du code avec des questions pour que d'autres peuvent vous hep –
@Moorthy - S'il vous plaît vérifier la réponse que j'ai ajouté. Ça va marcher. Si c'est utile, acceptez-le. – coderaizer