Design of playing mode in android music player

Source: Internet
Author: User

In a music player, the playback mode is generally automatically recognized after the music is played. The following logic code is provided. You can add the appropriate code as needed.

Public static final int ALL = 0; // ALL Loops

Public static final int SINGLE = 1; // SINGLE Loop

Public static final int RANDOM = 2; // RANDOM

// After playing a song (set the playing 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 playback

{

Position = 0; // The first line

}

Else

{

Position ++;

}

}

Else if (playMode = SINGLE) // SINGLE Loop

{

// Position does not need to be changed

}

Else if (playMode = RANDOM) // RANDOM

{

Position = (int) (Math. random () * listMusic. size (); // random playback

}

ElseSet (); // other playback Processing

}

}

When making a single loop, it is best not to design it like the code above. Because no actual position is given, the program may jump out of the BUG or even crash, the single loop I implemented is to listen to the user's mode selection. After the music is played, restart MediaPlayer.

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.