Я пробовал другие приложения для воспроизведения тех же видео, и эти приложения воспроизводились нормально. Только мое приложение Webview не воспроизводит видео, оно показывает черное видео, как изображение с символом воспроизведения, которое не воспроизводится и не перемещается.
**Below is my code:**
**Manifest.xml**
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="abc.co.za">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
**MainActivity.java**
public class MainActivity extends AppCompatActivity {
ProgressBar superProgressBar;
ImageView superImageView;
WebView superWebView;
LinearLayout superLinearLayout; //we will use it to access the
LinearLayout hosting the menu items
SwipeRefreshLayout superSwipeLayout;// layout for refreshing the
page when you swipe on your phone
String myCurrentUrl; //Url used by Share It menu item
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initializing our variables
superProgressBar =
(ProgressBar)findViewById(R.id.myProgressBar);
superImageView = (ImageView)findViewById(R.id.myImageView);
superWebView = (WebView)findViewById(R.id.myWebView);
superLinearLayout =
(LinearLayout)findViewById(R.id.myLinearLayout);
superSwipeLayout =
(SwipeRefreshLayout)findViewById(R.id.mySwipeLayout);
//add Progress bar and set the maximum count from zero
//it starts to count the load progress from zero to hundred
superProgressBar.setMax(100);
// WebView
superWebView.loadUrl ("https://asifunde.co.za/asifunde/login/index.php «); // и URL целевой страницы superWebView.getSettings (). setJavaScriptEnabled (true); // включить javascript загрузка в браузер superWebView.setWebViewClient (new WebViewClient () {// установка разрешения на использование клиента WebView (ie с помощью браузера)
@Override //when the page is loading the progress bar and favicon should be visible
public void onPageStarted(WebView view, String url, Bitmap favicon) {
superLinearLayout.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
@Override //when the page has finished loading the progress bar and favicon should disappear
public void onPageFinished(WebView view, String url) {
superLinearLayout.setVisibility(View.GONE);
superSwipeLayout.setRefreshing(false);//prevents the refreshing spinner fron running forever
super.onPageFinished(view, url);
myCurrentUrl = url;
}
});
superWebView.setWebChromeClient(new WebChromeClient(){ //setting chrome as the default browser
@Override
public void onProgressChanged(WebView view, int newProgress) {//get new progress bar on chrome
super.onProgressChanged(view, newProgress);
superProgressBar.setProgress(newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {//set title on the action bar
super.onReceivedTitle(view, title);
getSupportActionBar().setTitle(title);
}
@Override
public void onReceivedIcon(WebView view, Bitmap icon) {//set the imageView
super.onReceivedIcon(view, icon);
superImageView.setImageBitmap(icon);
}
});
//calling swipelayout to refresh the web page when swiped using your fingers
superSwipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
superWebView.reload(); //reload or refresh the webview element. Top of he page in this app
}
});
}
//Creating option menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater(); //inflating the menu
menuInflater.inflate(R.menu.super_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override //add onclick listener for each of the menu items
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){//switch statement for getting the menu items IDs
case R.id.menu_back:
onBackPressed();
break;
case R.id.menu_forward:
onForwardPressed();
break;
case R.id.menu_refresh:
superWebView.reload();
break;
case R.id.menu_share: //this invokes the share it menu item
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT,"https://play.google.com/store/apps/details?id=abcd"); //here you can put the url of APP playstore
shareIntent.putExtra(Intent.EXTRA_SUBJECT,"ABC Playstore Link");
startActivity(Intent.createChooser(shareIntent,"Share ABC Playstore URL"));
}
return super.onOptionsItemSelected(item);
}
//our custom menu to handle forward button click
private void onForwardPressed(){
if(superWebView.canGoForward()){
superWebView.goForward();
}else{
Toast.makeText(this,"Can't go further!",Toast.LENGTH_SHORT).show();
}
}
//setting the back button to go to the previous page
@Override
public void onBackPressed() {
if(superWebView.canGoBack()){
superWebView.goBack();
}else {
finish(); // destroys the current activity
}
}
}
**activity_main.xml**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/myLinearLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="30dp">
<ProgressBar
android:id="@+id/myProgressBar"
android:layout_weight="0.1"
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/myImageView"
android:src="@mipmap/ic_launcher"
android:layout_weight="0.9"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mySwipeLayout">
<WebView
android:id="@+id/myWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
**Code for the video on my website**
<div class="video-container">
<iframe src="https://drive.google.com/file/d/abcdujhfhdfhg/preview"
scrolling="no" seamless="" width="640" height="480"
frameborder="0"></iframe>
<div style="width: 80px; height: 80px; position: absolute; opacity:
0; right: 0px; top: 0px;"></div>