Done! Android RTMP streamBefore talking about how to use it, let's take a look at RTMP. Real Time Messaging Protocol (RTMP) is a Protocol owned by Adobe Systems. This protocol is a flash player developed by Adobe for audio and video streams. Later, part of the agreement was made public for public use. For more information, see here. This protocol is mostly used for IPTV and real-time on-demand video streaming, but it is also used for other applications.
On android, standard VideoView does not support RTMP playback. However, WebView can play RTMP streams. This solves the problem of playing RTMP streams, but I think web apps cannot provide a good interface and experience. Therefore, in this android RTMP example, we will use the third-party library-Vitamio live RTMP stream streaming media. After you reference Vitamio in the project, add the VideoView of Vitamio in your layout file:
Activity_main.xml
<LINEARLAYOUT android:orientation="vertical" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <IO.VOV.VITAMIO.WIDGET.VIDEOVIEW android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/vitamio_videoView" /> </LINEARLAYOUT>
In addition, please write your activity as follows:
MainActivity. java
package com.truiton.rtmpplayer; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import java.util.HashMap; import io.vov.vitamio.LibsChecker; import io.vov.vitamio.MediaPlayer; import io.vov.vitamio.widget.MediaController; import io.vov.vitamio.widget.VideoView; public class MainActivity extends ActionBarActivity { private static final String TAG = "MainActivity"; private String path; //private HashMap
options; private VideoView 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(new MediaController(this)); mVideoView.requestFocus(); mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mediaPlayer) { mediaPlayer.setPlaybackSpeed(1.0f); } }); } }
Although the above Code is clear and clear, it should be noted that you should modify the path of your RTMP stream. On android, RTMP streams may be played using a header path. Fortunately, the Vitamio RTMP player also supports this method. Therefore, the Vitamio library can be used for all types of RTMP streams. The above example will look like this:
Android RTSP Streaming MediaThe real-time stream protocol (RTSP) transmits content through a multimedia server. For example, YouTube uses the RTSP stream to publish content. The easy part of RTSP stream is that it can be completed through android-standard VideoView. For more information, see my VideoView example.
However, if you use the Vitamio library, you can play RTSP streams better. In fact, Vitamio also supports RTSP stream playback. The above process is the same, including the VideoView of Vitamio in the layout file, and the RTSP url specified by the PATH variable
mVideoView = (VideoView) findViewById(R.id.vitamio_videoView); path = "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 public void onPrepared(MediaPlayer mediaPlayer) { mediaPlayer.setPlaybackSpeed(1.0f); } });
Android m3u8 Streaming Media"Playing m3u8 videos on android" is one of the most common problems for android Developers. The simplest way to live video streams over Http is to use standard VideoView, but m3u8 streams can only be played on devices above android. Because HTTP/HTTPS live broadcast and HTTP/HTTPS progressive streaming protocols are introduced in Android 3.0, HTTPS is fully supported in android3.1.
If you want to implement HTTP Real-Time Streaming (HLS) that supports android m3u8 streams in earlier versions ). You should consider using the Vitamio library, which supports playing m3u8 videos over android API7. In the same way, use the VideoView of Vitamio in the layout file and specify the HTTP live streaming URL.
mVideoView = (VideoView) findViewById(R.id.vitamio_videoView); path = "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 public void onPrepared(MediaPlayer mediaPlayer) { mediaPlayer.setPlaybackSpeed(1.0f); } });
Playing m3u8 stream on Android with Vitamio wowould look something like this:
The following figure shows how to use Vitamio to play m3u8 streams on androi:
Android MMS streamThe Vitamio library is a powerful library and supports playing in Microsoft Media Server (MMS) streams. As a network-based streaming media protocol, MMS is mainly used for network broadcasting and radio broadcasting. The MMS stream used with Vitamio in anroid is no different from other protocols. All you need to do is change the PATH variable to a MMS url:
mVideoView = (VideoView) findViewById(R.id.vitamio_videoView); path = "mms://beotelmedia.beotel.net/studiob"; mVideoView.setVideoPath(path); mVideoView.setMediaController(new MediaController(this)); mVideoView.requestFocus(); mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mediaPlayer) { mediaPlayer.setPlaybackSpeed(1.0f); } });
ConclusionThrough the above discussion, we can say that Vitamio is a powerful multi-platform Library (ios and android ). You can use the Vitamio library to play multiple types of video formats and protocols, such as RTMP, RTSP, HTTP Live, and HTTP progressive stream protocols. Another good feature is that vitamio supports subtitle and multi-track playback. The only drawback of Vitamio is that it is not completely open-source. You may need to purchase a license to use it.