Implementation of mediaplayer playing network audio improved by Android

The previous article has introduced the basic usage of mediaplayer. Here we will explain the online playback function of mediaplayer in more depth. This paper mainly realizes the function of mediaplayer playing audio online. Because online video playing is more complex than online audio playing, we first introduce the implementation of online audio playing, which can help you gradually understand mediaplayer's online playing function.

Let's take a look at the running results of this program, as shown in the following figure:

The source code of main.xml is as follows:

Player.java is the core of this article. Player.java implements "progress bar update", "data buffer" and other functions. Although it is not a very complex function, it is a very useful function.

The source code of player.java is as follows:

test_ Musicplayer.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()) * player.mediaplayer.getduration ()。

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

Interested readers can personally debug the example code of this article. I believe it will promote everyone's understanding of Android programming.

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
分享
二维码
< <上一篇
下一篇>>