cant play this video Media player error in android studio solved

while playing streaming video inside the app, due to the slow net connection you may get the error ‘Cant play this video ‘. cant play this video Media player error in android studio solved In this post, I solve ‘Can’t play this video ‘ in media player using the android studio. In this post, I will solve  ‘Can’t play this video ‘ error that is generally come.
Let’s start 
cant play this video Media player error in android studio solved
Can’t play this video Media player error in android studio solved

 

Cant play this video Media player error in android studio solved

 

  1. copy                     ‘com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.2’            and paste it in your build.gradle
  2. use xml file

<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”
tools:context=”.MainActivity”>

<EditText
android:id=”@+id/textview”
android:layout_width=”match_parent”
android:layout_height=”80dp”
android:textSize=”20dp”/>
<Button
android:layout_width=”wrap_content”
android:id=”@+id/b1″
android:onClick=”nextp”
android:layout_height=”wrap_content”
android:layout_below=”@+id/textview”
android:text=”nextpage”/>

<Button
android:id=”@+id/b2″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_below=”@+id/textview”
android:layout_marginStart=”24dp”
android:layout_toEndOf=”@+id/b1″
android:onClick=”send”
android:text=”Submit” />

<Button
android:id=”@+id/b3″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_below=”@+id/textview”
android:layout_marginStart=”12dp”
android:layout_toEndOf=”@+id/b2″
android:onClick=”send”
android:text=”Submit” />

<FrameLayout
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:layout_below=”@+id/b1″>

<com.github.rtoshiro.view.video.FullscreenVideoLayout
android:id=”@+id/videoview”
android:layout_width=”match_parent”
android:layout_height=”match_parent” />
</FrameLayout>

</RelativeLayout>

Use java file

package com.sumit.hopeitwillwork;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.github.rtoshiro.view.video.FullscreenVideoLayout;

import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends Activity {

FullscreenVideoLayout videoLayout;
Runnable runnable,runnable1;
Timer timer,timer1;
Handler handler,handler1;
Button bu;

EditText e1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText) findViewById(R.id.textview);
videoLayout = (FullscreenVideoLayout) findViewById(R.id.videoview);
videoLayout.setActivity(this);
bu=(Button)findViewById(R.id.b2) ;
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}

public void send(View view) {
String urll = e1.getText().toString();
Uri videoUri = Uri.parse(urll);
try {
videoLayout.setVideoURI(videoUri);

} catch (IOException e) {
e.printStackTrace();
}
handler = new Handler();
final int delay = 3000;

handler.postDelayed(new Runnable(){
public void run(){
nextp(null);
handler.postDelayed(this, delay);
}
}, delay);

}
public void nextp(View view) {
Integer currentposition = videoLayout.getCurrentPosition();
Toast.makeText(this, “Download Started…”, Toast.LENGTH_LONG).show();
videoLayout.getDuration();
videoLayout.seekTo(60000*10);
videoLayout.seekTo(currentposition);
videoLayout.start();
}
}

first i will show you example that pop up the error

 

This was my xml file(that give  me error)

<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”
tools:context=”.Main2Activity”>
<LinearLayout
android:layout_width=”match_parent”
android:orientation=”vertical”
android:layout_height=”wrap_content”>

<EditText
android:id=”@+id/textview”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:textSize=”20dp” />

<Button
android:id=”@+id/b2″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_below=”@+id/textview”
android:layout_marginStart=”24dp”
android:layout_toEndOf=”@+id/b1″
android:onClick=”send”
android:text=”Submit” />

<VideoView
android:id=”@+id/videoview”
android:layout_width=”match_parent”
android:layout_height=”match_parent” />
</LinearLayout>
<LinearLayout
android:layout_width=”wrap_content”
android:id=”@+id/prog1″
android:visibility=”visible”
android:layout_height=”wrap_content”
android:layout_marginTop=”300dp”
android:layout_marginLeft=”150dp”>

<ProgressBar
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />

</LinearLayout>
</RelativeLayout>

This is my Java file

package com.sumit.hopeitwillwork;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.widget.VideoView;

import java.io.IOException;

public class Main2Activity extends Activity {

VideoView videoLayout;
LinearLayout layout;
EditText e1;
Button bu;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
e1 = (EditText) findViewById(R.id.textview);
bu=(Button)findViewById(R.id.b1);
videoLayout = (VideoView) findViewById(R.id.videoview);
layout=(LinearLayout)findViewById(R.id.prog1);
}

public void send(View view) {
Uri videourl=Uri.parse(e1.getText().toString());
videoLayout.setVideoURI(videourl);
videoLayout.requestFocus();
videoLayout.setOnInfoListener(new MediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mediaPlayer, int i, int i1) {
if(i==mediaPlayer.MEDIA_INFO_BUFFERING_START)
{
layout.setVisibility(View.VISIBLE);
}
else if(i==mediaPlayer.MEDIA_INFO_BUFFERING_END)
{
layout.setVisibility(View.INVISIBLE);
}
return false;
}
});
videoLayout.start();

}
public void getcurr(View view)
{
Integer currentposition = videoLayout.getCurrentPosition();
videoLayout.seekTo(60000*10);
videoLayout.seekTo(currentposition);
String i=Integer.toString(currentposition);
bu.setText(i);
}
}

cant play this video Media player error in android studio solved.

final word:- 

if you have any doubt or problem regarding Can’t play this video Media player error in android studio solved. Then you can feel free to ask the question. So, write your problem in the comment box. Because we are here to solve your all doubt.

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *