How Android live streaming rtmp streams

Source: Internet
Author: User

  • Original link: How to Stream RTMP live in Android
  • Original Author: Mohit Gupt
  • Development technology Front www.devtf.cn
  • Translator: ayyb1988
  • Reviewer: chaossss
  • Status: Complete

On Android, video/audio streaming is a very rare part of the spotlight. RTMP (Real time Messaging Protocol) is indispensable whenever we discuss streaming media. RTMP is a basic video/audio streaming protocol, but unfortunately Android standard Videoview does not support rtmp playback. Therefore, if you want to play rtmp live streaming on Android, you must use a library that supports the RTMP protocol. In this tutorial we will discuss how to play streaming media transmitted by the RTMP protocol by using the Android [Vitamio] (https://www.vitamio.org/en/) library.

Android Vitamio Library

Vitamio is an open source project based on FFmpeg on Android and iOS. Vitamio provides us with a clean, simple, comprehensive, real hardware accelerator decoder and renderer Api,vitamio is a very powerful library that supports a wide variety of audio and video formats such as FLV, TS/TP, WMV, DivX, XviD and many other standard formats. What's different is that it also supports similar. mkv and. SRT embedding and external subtitle playback. But it comes with a license, so be sure to get certified before using it. In this Android rtmp example, we will discuss not only the rtmp live stream, but also the m3u8 stream (HLS), RTSP Stream, and MMS (Microsoft Media stream). First let's refer to the Vitamio library in our project.

The steps for referencing the Vitamio library in Android Studio are as follows:
    1. Download Vitamio Bundle Https://github.com/yixia/VitamioBundle
    2. Unzip and File->import Module on Android Studio
    3. Specify to Vitamiobundle path, select Vitamio folder click Finish
    4. Add Dependent Project (': Vitamio ') in Build.gradle (Module:app) Dependency section
    5. Open Build.gradle (Module:vitamio)-Change the minimum SDK version to 7
    6. Don't forget to add Internet permissions in Manifest.xml
    7. Complete!
Android rtmp Stream

Before we tell you how to use it, let's get to the next rtmp. Real time Messaging Protocol (RTMP) is an agreement owned by Adobe Systems. The agreement is a Flash player owned by Adobe to develop audio and video streams. Later portions of the agreement were publicly available for public use. See here for more information. This protocol is mostly used for IPTV and real-time video on demand streaming, but it is also used for other leads.

On Android, the standard Videoview does not support rtmp playback. But WebView can play rtmp streams. This solves the problem of playing rtmp streams, but I don't think web apps can provide a good interface and experience. So in this example of the Android rtmp we will use third-party libraries to stream streaming media-vitamio live rtmp streams. After referencing Vitamio in your project, add the Vitamio videoview to your layout file:

Activity_main.xml

    <?xml version= "1.0" encoding= "Utf-8"?>    <linearlayout  xmlns: Android  = "http://schemas.android.com/apk/res/android"  android:layout_width  =" match_parent " android:layout_height  =" match_parent " and Roid:orientation  =;         <io.vov.vitamio.widget.VideoViewandroid:id="@+id/vitamio_videoview"  Android:layout_width="Wrap_content"android:layout_height="Wrap_content" />                                        </linearlayout>

Please also write your activity as follows:

Mainactivity.java

     PackageCom.truiton.rtmpplayer;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;Importandroid.support.v7.app.ActionBarActivity;ImportJava.util.HashMap;ImportIo.vov.vitamio.LibsChecker;ImportIo.vov.vitamio.MediaPlayer;ImportIo.vov.vitamio.widget.MediaController;ImportIo.vov.vitamio.widget.VideoView; Public  class mainactivity extends actionbaractivity {        Private Static FinalString TAG ="Mainactivity";PrivateString path;//private hashmap<string, string> options;        PrivateVideoview Mvideoview;@Override        protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);if(! Libschecker.checkvitamiolibs ( This))return;            Setcontentview (R.layout.activity_main);            Mvideoview = (videoview) Findviewbyid (R.id.vitamio_videoview); Path ="Rtmp://rrbalancer.broadcast.tneg.de:1935/pw/ruk/ruk";/*options = new hashmap<> ();            Options.put ("Rtmp_playpath", "" ");            Options.put ("Rtmp_swfurl", "" ");            Options.put ("Rtmp_live", "1"); Options.put ("Rtmp_pageurl", "" "); * *Mvideoview.setvideopath (path);//mvideoview.setvideouri (Uri.parse (path), options);Mvideoview.setmediacontroller (NewMediacontroller ( This));            Mvideoview.requestfocus (); Mvideoview.setonpreparedlistener (NewMediaplayer.onpreparedlistener () {@Override                 Public void onprepared(MediaPlayer MediaPlayer) {Mediaplayer.setplaybackspeed (1.0f);        }            }); }    }

Although the above code is clear, it is important to note that you should modify the path of the rtmp stream you are playing. On Android, it is sometimes possible to play rtmp streams with a header path. Fortunately, the Vitamio rtmp player also supports this approach. Therefore, all types of rtmp streams can use the Vitamio library. The example above would look like this:

Android RTSP Streaming Media

Live Streaming Protocol (RTSP) transmits content through a multimedia server, such as YouTube, which publishes content using RTSP streaming. The easy part about the RTSP stream is that it can be done with Android standard Videoview, for more information, please refer to my videoview example.

But if you use the Vitamio library, you can play the RTSP stream better. In fact Vitamio also supports the playback of RTSP streams. And the above procedure is the same, including the Vitamio videoview in the layout file, and the RTSP URL specified using the PATH variable

    mVideoView = (VideoView) findViewById(R.id.vitamio_videoView);    "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";    mVideoView.setVideoPath(path);    mVideoView.setMediaController(new MediaController(this));    mVideoView.requestFocus();    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {        @Override        publicvoidonPrepared(MediaPlayer mediaPlayer) {            mediaPlayer.setPlaybackSpeed(1.0f);        }    });
Android m3u8 Streaming Media

"How to play m3u8 video on Android" is one of the most common problems for Android developers. The simplest way to stream live video via the HTTP protocol is to use standard videoview. However, the m3u8 stream can only be played on devices above android3.0. Since the introduction of Http/https Live and HTTP/HTTPS progressive streaming protocols in Android 3.0, HTTPS is fully supported in android3.1.

If you want to implement HTTP live streaming (HLS) on an earlier version that supports Android m3u8 streaming. You should consider using the Vitamio library, which supports playing m3u8 above Android API7. Using the same method, use the Vitamio videoview in the layout file, and specify the HTTP live streaming URL.

    mVideoView = (VideoView) findViewById(R.id.vitamio_videoView);    "http://93.184.221.133/00573D/236/236-0.m3u8";    mVideoView.setVideoPath(path);    mVideoView.setMediaController(new MediaController(this));    mVideoView.requestFocus();    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {        @Override        publicvoidonPrepared(MediaPlayer mediaPlayer) {            mediaPlayer.setPlaybackSpeed(1.0f);        }    });

Playing m3u8 stream on Android with Vitamio would look something like this:
Use Vitamio on Androi to play the m3u8 stream effect as follows:

Android MMS Stream

The Vitamio library is a powerful library that also supports playback in Microsoft Media Server (MMS) streams. MMS is a network streaming media protocol, which is mainly used for webcast and radio broadcasting. Using Vitamio for MMS streaming in Anroid is not different from other protocols. All you need to do is change the path variable to point to an MMS URL:

    mVideoView = (VideoView) findViewById(R.id.vitamio_videoView);    "mms://beotelmedia.beotel.net/studiob";    mVideoView.setVideoPath(path);    mVideoView.setMediaController(new MediaController(this));    mVideoView.requestFocus();    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {        @Override        publicvoidonPrepared(MediaPlayer mediaPlayer) {            mediaPlayer.setPlaybackSpeed(1.0f);        }    });
Conclusion

Through the discussion above, it is possible to say that Vitamio is a powerful multi-platform library (iOS and Android). By using the Vitamio library you can play multiple types of video formats and protocols such as RTMP, RTSP, HTTP Live, and HTTP progressive streaming protocol. Another good feature is that Vitamio supports subtitles and multi-track playback. The only drawback of Vitamio is that it is not entirely open source. You may need to purchase a license to use it. Hopefully this will help. Contact us for more updates via Facebook, Google + and Twitter.

How Android live streaming rtmp streams

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.