Android app-simple and music player with phone listening added

Source: Internet
Author: User
Android app-simple and beautiful music players add phone monitors


In September 2nd, the simplified and beautiful music players started Stage 1



Stage 1 has completed the following functions:



 



1. automatically display the music list



2. Click the list to play the music.



3. Long press List dialog box



4. Pause music



5. Last music



6. Next music



7. automatically play the next song



8. Single Loop



9. All Loops



10. Random playback



 



In stage 1, you are ready to complete the following functions:



1. The previous blog has implemented the lyrics display (to implement the lyrics scrolling function ).



2. It's easy to listen to what this blog will talk about



3. Volume Control



4. Obtain album Images



5. Download the lyrics online



6. Search for music online



7. Download music online



8. Implement interesting functions-zhige



9. UI beautification-implement album reflection



10. switch between the left and right Interfaces



11. display the playback status in the notification bar.



12. Implement desktop widgets for music playback






If you have any suggestions for these functions, you can leave a message directly.



Call Status MonitoringCodePreviously, I posted the appconstant class, which is only used to store the playback control information. Some netizens said they would like to take a look, so I 'd like to paste it here.



 


 



Package com. WWJ. Sb. Domain;

/ * *
* apply the constant class
* @ author WWJ
*
* /
Public class AppConstant {
Public class PlayerMsg {
Public static final int PLAY_MSG = 1; / / play
Public static final int PAUSE_MSG = 2; / / pause
Public static final int STOP_MSG = 3; / / stop
Public static final int CONTINUE_MSG = 4; / / to continue
Public static final int PRIVIOUS_MSG = 5; / / a
Public static final int NEXT_MSG = 6; / / a
Public static final int PROGRESS_CHANGE = 7; // schedule change
Public static final int PLAYING_MSG = 8; // playing now
}
}





 



Well, we should continue to improve the simplified and beautiful music players of Xiao Wu, because a good application software should take into account various situations. For the music player, if a call is made during the playing of music, it may be "people who will never call you". If your music is still playing in the background at this time, I think you will go crazy, people who will never call you may never call you. This is just a joke, so you have to consider this situation. As long as you call, the player should be able to pause so that you can make a call. The following implementation is very simple and I will not explain it much. I will directly go to the Code:






1. Add Permissions



 


 



<!--</span--> -- read the phone status permission -->
< USES - the permission of the android: name = "android. Permission. READ_PHONE_STATE" / >
< USES - the permission of the android: name = "android. Permission. PROCESS_OUTGOING_CALLS" / >


2. Get the telephonymanager object and call the listen method to listen to the incoming call status.



 



 


// add call listening event
TelephonyManager telManager = (TelephonyManager) getSystemService(context.telephony_service); // access system services
TelManager. Listen (new MobliePhoneStateListener (),
PhoneStateListener. LISTEN_CALL_STATE);


3. Listener class



 



 


/ * *
*
* @ author WWJ
* phone listener class
* /
Private class MobliePhoneStateListener extends PhoneStateListener {
@ Override
Public void onCallStateChanged(int state, String incomingNumber) {
The switch (state) {
Case telephonymanager.call_state_idle: // hung state
Intent Intent = new Intent(playeractivity.this, playerservice.class);
PlayBtn. SetBackgroundResource (R.d rawable. Play_selector);
Intent. SetAction (" com. WWJ. Media. MUSIC_SERVICE ");
Intent. PutExtra (" MSG ", AppConstant. PlayerMsg. CONTINUE_MSG); // keep playing the music
StartService (intent);
IsPlaying = false;
IsPause = true;
Break;
Case telephonymanager.call_state_offhook: // call status
Case telephonymanager.call_state_ringing: // ringing state
Intent intent2 = new Intent(playeractivity.this, playerservice.class);
PlayBtn. SetBackgroundResource (R.d rawable. Pause_selector);
Intent2. SetAction (" com. WWJ. Media. MUSIC_SERVICE ");
Intent2. PutExtra (" MSG ", AppConstant. PlayerMsg. PAUSE_MSG);
StartService (intent2);
IsPlaying = true;
IsPause = false;
Break;
Default:
Break;
}
}
} 





 






 


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.