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.