Implementation of mediaplayer playing network video improved by Android

Earlier, I explained mediaplayer playing network audio, mainly introduced mediaplayer's methods of buffering and progress bar control of network audio, and this article will explain mediaplayer's methods of playing network video. Playing network video requires only one more surfaceview than playing network audio. After you are familiar with mediaplayer playing network audio, I believe you can quickly master the playing network video described in this article.

Let's take a look at the screenshot of the program in this article, as shown below:

The video of this program comes from http://daily3gp.com , you can replace the video link in the program and try other videos.

The source code of main.xml is as follows:

Player.java is the core of this article. Player.java implements functions such as "progress bar update", "data buffer" and "surfaceholder life cycle". Among them, "surfaceholder life cycle" is the biggest difference between video and audio playback. Some resources can be created / released through surfacecreated(), surfacetested(), and surfacechanged(). Note the following:

Some videos cannot be played by Android player. When they cannot be played, videoheight = 0 and videowidth = 0 to judge whether to play the video.

The source code of player.java is as follows:

test_ Videoplayer.java is the main program and is responsible for calling the player class. The key part is seekbarchangeevent. The event dragged by seekbar: the progress of seekbar is the number from 0 to seekbar. Getmax(), while the parameter of mediaplayer. Seekto() is the number from 0 to mediaplayer. Getduration(), so the parameter of mediaplayer. Seekto() is (progress / seekbar. Getmax()) * mediaplayer. Getduration().

test_ The source code of videoplayer.java is as follows:

Interested readers can test the example code of this article by themselves. I believe it can be used as a reference for Android program development.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>