Learn Android audio and video together

The Android multimedia framework supports various common media types and can easily integrate audio, video and images into the app. Mediaplayer API allows you to play audio or video from application resources , file systems, or data stream resources on the network. This article demonstrates how to play audio and video files through API to obtain good performance and pleasant user experience. It is only for learning and sharing. If there are deficiencies, please correct them.

Play the audio file on the page as follows:

1. Prepare the resource file and play it

2. Pause playback

3. Stop

4. Release resources (when the page is destroyed, the playback resources should also be released at the same time)

5. Create objects through static functions

When the page is closed, the audio file can also be played in the background. The steps are as follows:

1. Define the background service. When the service is started, create the mediaplayer object and register the service receiving object.

2. Operation receiver is defined as follows:

3. Start service

4. The foreground activity controls the playback and pause of audio by sending broadcast commands

5. Through the background service, you need to register in the androidmanifest.xml file

To play video files through videoview, you only need to set the resource URI, as follows:

Play the video file through mediaplayer, and then display the video content through surfaceview. The specific steps are as follows:

1. Start and set the display content through setdisplay

2. Suspension and stop

3. Resource release

If you want to play video, you need corresponding permission settings and obtain the requested permission during installation

Embracing wood, born at the slightest; The nine storey platform starts from the earth; A thousand mile trip begins with one step.

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