The design of playing mode in the Android music player

Source: Internet
Author: User
Tags final

In the music player, the playback mode is usually placed in the music after the automatic recognition, the following gives the logical code, you can add appropriate code as needed

public static final int all = 0;//full loop public  
static final int single = 1;//singles loop public  
static final int RANDOM = 2;//random  
      
//A song after playback is complete (set playback mode here) public  
 class Completed implements Oncompletionlistener  
 {  
 @Override Public
 void Oncompletion (MediaPlayer MP)  
 {  
 if (PlayMode = ALL)//All loops  
 {  
 if (position = = Listmusic.size ()-1)//default loop play  
 {  
 position = 0;// First  
 }  
 else
 {  
 position++;  
 }  
 }  
 else if (PlayMode = = single)//singles loop  
 {  
 //position do not need to change  
 }  
 else if (PlayMode = = RANDOM)//random  
 {  
 position = (int) (Math.random () *listmusic.size ());//Random play  
 }  
 Elseset ()//other playback processing  
 }  
 }

Note: When making a single cycle, it is best not to like the code on the design, because there is no actual position, the program may jump out of the bug, or even crash, I realized that the single loop is listening to the user's mode of choice, when the music playback finished, restart the MediaPlayer on it.

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.