Put Below Code into your Application.
MainActivity.java File:-
public class MainActivity extends Activity {
public static String url = "rtsp://v3.cache8.c.youtube.com/CiILENy73wIaGQmXovF6e-Rf-BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
private VideoView videoView = null;
private ProgressBar prog = null;
private Context ctx = null;
private MediaController mediaController = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.main);
ctx = this;
prog = (ProgressBar) findViewById(R.id.prog);
videoView = (VideoView) findViewById(R.id.video);
Uri video = Uri.parse(url);
mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
// TODO Auto-generated method stub
Toast.makeText(ctx, "Error occured", 500).show();
return false;
}
});
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
prog.setVisibility(View.GONE);
videoView.start();
}
});
}
@Override
protected void onDestroy() {
try {
videoView.stopPlayback();
} catch (Exception e) {
//
}
super.onDestroy();
}
}
Main.xml File:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView
android:id="@+id/video"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
<ProgressBar
android:id="@+id/prog"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center" />
</FrameLayout>
</LinearLayout>
And Give Below Permission into your Manifest.xml file.
<uses-permission android:name="android.permission.INTERNET"/>
Enjoy:--)
Don’t forget to provide feedback or follow this blog, if you find this blog is useful.
MainActivity.java File:-
public class MainActivity extends Activity {
public static String url = "rtsp://v3.cache8.c.youtube.com/CiILENy73wIaGQmXovF6e-Rf-BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
private VideoView videoView = null;
private ProgressBar prog = null;
private Context ctx = null;
private MediaController mediaController = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.main);
ctx = this;
prog = (ProgressBar) findViewById(R.id.prog);
videoView = (VideoView) findViewById(R.id.video);
Uri video = Uri.parse(url);
mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
// TODO Auto-generated method stub
Toast.makeText(ctx, "Error occured", 500).show();
return false;
}
});
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
prog.setVisibility(View.GONE);
videoView.start();
}
});
}
@Override
protected void onDestroy() {
try {
videoView.stopPlayback();
} catch (Exception e) {
//
}
super.onDestroy();
}
}
Main.xml File:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView
android:id="@+id/video"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
<ProgressBar
android:id="@+id/prog"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center" />
</FrameLayout>
</LinearLayout>
And Give Below Permission into your Manifest.xml file.
<uses-permission android:name="android.permission.INTERNET"/>
Enjoy:--)
Don’t forget to provide feedback or follow this blog, if you find this blog is useful.
Hi dipak,
ReplyDeletenice tutorial, but when we rotate the device from potrait to landscape the video is playing from starting onwards.. when in landscape the videoview is not covering complete screen...
Please help me in this regards.
thank u
not working in setonerror() showing error
ReplyDeletethanks bro..
ReplyDeletei have tried this code but showing video coudn't not played..
ReplyDeletethis code when you intall it on emultor it will not work but try it on adevice it works ok
Deletenice friend,keep it up....
ReplyDeleteHow can we get the rtsp link can you please help i'm not getting correct solution
ReplyDeleteContact Me:kirankumar667.2015@gmail.com
Thanks for your code.
Very Nice Guidance
ReplyDeletehi friends I find the new example of Play Video File - Android Example
ReplyDeletehttp://androidexample.com/Play_Video_File_-_Android_Example
/index.php?view=article_discription&aid=124&aaid=144
i geting error in "Sorry, this Video cannot played."
ReplyDeletei am trying to play youtube video it gives error message as Cant't play this video dialoge
ReplyDelete
ReplyDeleteWe’ve been stumbling around the internet and found your blog along the way.
We love your work! What a great corner of the internet :)
beds
bed
mattress
mattresses
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeleteJava Training in Pune
thanks for sharing this information
ReplyDeleteBlue Prism Training in Bangalore
Blue Prism Training in BTM
RPA Training in BTM
RPA Training in Bangalore
Android Training in Bangalore
Android Training in Bangalore
Google Cloud Training in Bangalore
Azure DevOps training in Bangalore
nice post this is useful message
ReplyDeleteaws training center in chennai
aws training in chennai
aws training institute in chennai
best angularjs training in chennai
angular js training in sholinganallur
angularjs training in chennai
azure training in chennai
Thanks for sharing this information...
ReplyDeleteAngularJS Training in Bangalore | AngularJS Course Fees | AngularJS 6 - i Digital Academy - AngularJS Training in Bangalore - Learn AngularJS 6 from Expert Real-time Trainers
at i Digital Academy with Live Projects and Placement Assistance. Book a Free Demo Today.
Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
ReplyDeleteangularjs online training
best angularjs online training
top angularjs online training
Your article looks really adorable, here's a site link i dropped for you which you may like.경마
ReplyDeleteI enjoy reading all of your post. I wanted to write
ReplyDeletea little comment to support you. 온라인카지노
Smm Panel
ReplyDeletesmm panel
iş ilanları
instagram takipçi satın al
hirdavatciburada.com
beyazesyateknikservisi.com.tr
SERVİS
tiktok jeton hilesi
ReplyDeleteI'm writing on this topic these days,
블랙잭사이트
This post is really magnificent.
블랙잭사이트
ReplyDeleteWow! Thank you!
검증카지노
Thanks for sharing post.
온라인카지노
agyan nyo nalang ng number.
ReplyDeletesundan nyo to:
65. Santos, San Dioniso
50. Brabante- San Dionisio
60. Contemplacion - BF Homes
71. Asadon- San dionisio
14. Biongan- San Isidro
20. Bion-San Dionisio
54. Galman- Moonwalk
17.Hermita- San Dionisio
kung ano po ung number nyo sa taas
64. Condino -SAN DIONISIO
57. Suano- San isidro
62. Mugar - Marcelo Green
63. Corpuz - Moonwalk
66. Yongzon Jr. - Don Bosco
6. Del Rosario - San Antonio