Video/audio playback (Android tutorial 7)

Source: Internet
Author: User

 

1. MediaPlayer is used for audio and video playback. To use MediaPlayer for video/audio playback, follow these steps:

 

A. Generate a MediaPlayer object. Use different generation methods based on the playback file (refer to MediaPlayer API );

 

B. After obtaining the MediaPlayer object, call different methods based on your actual needs, such as start (), storp (), pause (), and release.

 

Note: When you do not need to play the video, release the playback file connected to the MediaPlayer object. (MediaPlayer objects are generally used for audio playback)

 

2. Video Playback is mainly implemented through the VideoView class and MediaController class. The implementation steps are as follows:

 

A. Generate a VideoView object, which can be implemented through an xml file or java code.

 

B. Create a video playback file for the generated VideoView object: VideoView. setVideoPath (String path);. Or VideoView. setVideoURI (Uri uri );

 

C. Generate a MediaController object, which can be implemented through an xml file or java code.

 

D. Associate the VideoView object with the MediaController object:

 

VideoView. setMediaController (MediaController mc );

 

MediaController. setMediaPlayer (VideoView vv );

 

MediaPlayer object operations are as follows: (In my Android album, the name is mediaplayer_state_di#image ).

 



From tianshijianbing1989

Related Article

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.