In the post Android: How to play RTSP or HLS video streams, there is one missing video streaming issue leaving unresolved: the RTMP videos.
This post outlines how to implement rendering RTMP videos on Android platform. This is far from a trivial problem, but I will get it done quickly using the open source Vitamio library.
- Download the Vitamio bundle from https://github.com/yixia/VitamioBundle, extract the zip file if you downloaded the zip file, or if you pull the source out of it, you will see a folder called “vitimio” there.
- In Android Studio, create a project, let’s call it VideoStreamPlayer.
- In Android Studio, go to File->Import Module, navigate to “VitamioBundle-master” folder you extracted or pulled from the source, select “vitamio” folder and press finish to import the library.
- Add compile project(‘:vitamio’) in build.gradle(Module: app) dependencies section
- Add the internet permission in your manifest, outside <application> node
<uses-permission android:name=”android.permission.INTERNET”/>
- Build the app and make sure it works.
- Go to the activity layout, add below code:
<io.vov.vitamio.widget.VideoView
android:id=”@+id/vitamio_videoView”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />
- In the activity class, add below code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);if (!LibsChecker.checkVitamioLibs(this)) //Important!
return;setContentView(R.layout.activity_main);
mVideoView = (VideoView) findViewById(R.id.vitamio_videoView);
path = “rtmp://rrbalancer.broadcast.tneg.de:1935/pw/ruk/ruk”;
mVideoView.setVideoPath(path);
mVideoView.requestFocus();
}
Rebuild and run. That is it!
Tip 1: to make it easier to debug and troubleshooting, you might first make sure an rtmp stream is valid. You can do so by opening the RTMP url in VLC player.
Tip 2: If nothing displays in the activity, make sure if (!LibsChecker.checkVitamioLibs(this)) is called.
Tip 3: Depending on the network, some RTMP might be very slow, so be patient when it loads.
hey , first of all , thanks for the tutorial is really heplfull. i just have a litle problem. i can not play rtmp streams with vitamio. i just can play rtsp and other formats, but not the rtmp url. i just have this error on the logcat : E/Vitamio[Player]: Native libs libffmpeg.so not exists!.
I am very grateful if you can assist me a little about what’s going on that error.
thanks.
This might be incorrect dependency problem. Make sure you have correctly configured the gradle setting file, as outlined above.
Hi Tahanks for the tutotial, it helped me, but the video is not get played, I am getting a pop-up i mean dialog with the msg – this video can’t play
when i see logcat : follows as please help to play the videos
12-11 18:04:36.579 24204-24204/? I/Vitamio[4.2.6][Player]: VPLAYER INIT BEGIN
12-11 18:04:36.579 24204-24204/? I/Vitamio[4.2.6][Player]: Application package name: com.example.vidhya.videostreamplayer
12-11 18:04:36.579 24204-24204/? I/Vitamio[4.2.6][Player]: VPLAYER INIT END
Copyright (c) YIXIA (http://yixia.com).
12-11 18:04:36.579 24204-24204/? I/Vitamio[4.2.6][Player]: THIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)
12-11 18:04:36.579 24204-24204/? I/Vitamio[4.2.6][Player]: Application package name: com.example.vidhya.videostreamplayer
12-11 18:04:36.579 24204-24204/? I/Vitamio[4.2.6][Player]: Copyright (c) YIXIA (http://yixia.com).
12-11 18:04:36.579 24204-24204/? I/Vitamio[4.2.6][Player]: THIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)
12-11 18:04:36.579 24204-24204/? I/Vitamio[4.2.6][Player]: Application package name: com.example.vidhya.videostreamplayer
12-11 18:04:36.579 24204-24204/? I/Vitamio[4.2.6][Player]: PREPARE SIG: 0
12-11 18:04:36.579 24204-24980/? I/Vitamio[4.2.6][Player]: THREAD PREPARE START
12-11 18:04:36.579 24204-24980/? I/Vitamio[4.2.6][Player]: THREAD PREPARE ATTACHED
12-11 18:04:36.579 24204-24980/? I/Vitamio[4.2.6][Player]: Copyright (c) YIXIA (http://yixia.com).
12-11 18:04:36.579 24204-24980/? I/Vitamio[4.2.6][Player]: THIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)
12-11 18:04:36.579 24204-24980/? I/Vitamio[4.2.6][Player]: OPEN FILE rtmp://rrbalancer.broadcast.tneg.de:1935/pw/ruk/ruk
Make sure your testing rtmp is valid. The example “rtmp://rrbalancer.broadcast.tneg.de:1935/pw/ruk/ruk”; may or may not work! Use your own url and retry!
Thank you, So much, Helped me alot
Thanks for the tutorial , it is really nice. I have one problem , I want to play audio .mp3 , How can I play audio with this library.. Thanks In Advance
Showing Error in mVedioView can you help me