i am a new to android development so dont be harsh
I am creating an android application that contains a webview. The webview has many links to live stream.
After reading various posts, i understand that it is really difficult and complicated (as i have tried) to get the video played in webview itself as webview doesn't have/ support many features for video streaming
My question is: HOW DO I OPEN UP MXPLAYER AND PLAY THE STREAM WHENEVER THE USER SELECTS A SPECIFIC LINK IN THE WEBVIEW?
I am just testing this on my own device so want to keep it specific to mx player as i already have that installed
I have tried the following:
public class WebPageLoader extends Activity {
final Activity activity = this;
WebView webView;
private String pknamepro;
String homePage = "";
String specificWebURL = "";
public WebPageLoader(){
pknamepro = "com.mxtech.videoplayer.pro";
}
private void startMx(String url)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("com.mxtech.videoplayer.pro", "com.mxtech.videoplayer.pro.ActivityScreen"));
intent.setData(Uri.parse(url));
intent.putExtra("secure_uri", true);
startActivity(intent);
return;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webpageloader);
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setSupportZoom(false);
webView.getSettings().setBuiltInZoomControls(false);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
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)
{
Toast.makeText(getApplicationContext(), "Internet connection down" + description, Toast.LENGTH_SHORT).show();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url.contains("rtmp")|| url.contains(specificWebURL) || url.startsWith("rtmpe")|| url.startsWith("udp")) {
startMx(url);
return true;
}
view.loadUrl(url);
return true;
}
});
webView.loadUrl(homePage);
}
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
// Save the state of the WebView
webView.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
// Restore the state of the WebView
webView.restoreState(savedInstanceState);
}
public void onBackPressed() {
if(webView.canGoBack() == true){
webView.goBack();
}else{
webView.goBack();
}
}
As you can see, i have tried it by checking the url as well as tried to hard code the url but neither work.
It seems as if it doesn't do any of the above checks and tries to play the video in webview it self because whenever i click on any of the links, a new page opens saying "Error loading player: No playable sources found" instead of opening mxplayer on my device.