RSS

Android: How to play RTMP video streams

20 Sep

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.

  1. 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.

  2. In Android Studio, create a project, let’s call it VideoStreamPlayer.

  3. 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.

  4. Add compile project(‘:vitamio’) in build.gradle(Module: app) dependencies section

    image.png

  • 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.

Advertisements
 
6 Comments

Posted by on September 20, 2015 in Android, Programming

 

Tags: , , , , , , , ,

6 responses to “Android: How to play RTMP video streams

  1. george

    October 9, 2015 at 3:01 am

    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.

     
  2. xinyustudio

    October 9, 2015 at 11:53 am

    This might be incorrect dependency problem. Make sure you have correctly configured the gradle setting file, as outlined above.

     
  3. Vidhyadhari

    December 11, 2015 at 8:38 pm

    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

     
  4. xinyustudio

    December 11, 2015 at 9:12 pm

    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!

     
  5. Vidhyadhari

    December 14, 2015 at 10:17 am

    Thank you, So much, Helped me alot

     
  6. Jan

    August 23, 2016 at 9:50 pm

    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

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: