Is it possible to check if a WebView is playing a Video at the moment and if yes to get the http://... .mp4/ URL of this Video to download?
I already have tried this code:
public void onLoadResource(WebView view, final String url){
super.onLoadResource(view, url);
if(url.endsWith(".mp4") & !url.contains(".jpg") & !url.contains(".png")){
AlertDialog.Builder video_downloaden = new AlertDialog.Builder(SearchActivity.this);
video_downloaden.setTitle("Video downloaden?");
video_downloaden.setMessage("Download Video?");
video_downloaden.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
DownloadManager.Request request_video = new DownloadManager.Request(Uri.parse(url));
request_video.allowScanningByMediaScanner();
request_video.setVisibleInDownloadsUi(false);
DownloadManager downloadManager2 = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
request_video.setDestinationInExternalFilesDir(getApplicationContext(), DIRECTORY_DOWNLOADS, File.separator + ".Videos" + File.separator + "video" + video_number);
downloadManager2.enqueue(request_video);
Toast.makeText(SearchActivity.this,"Download started",Toast.LENGTH_LONG).show();
}
});
video_downloaden.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
video_downloaden.show();
}
}
But with onLoadResource()
the AlertDialog is shown all the time and the download doesn't work every time...
So my question is, if there is any other opportunity to check if the WebView is playing a Video and to get the Video url?