Android Network Radio--using Vitamio decoding (ii)

Source: Internet
Author: User

Mentioned in the previous Android network Radio-using Vitamio decoding (a) to achieve the playback of streaming media files, but only play once, here can randomly click on the left side of the menu to play, but the Vitamio is not very stable, some URIs have expired can not play, I downloaded a PC version of the network radio to compare, if the PC can play, here is also able to play, using some pictures on the internet, first look at the modified interface



Because there is currently no network, only the name is displayed



Program directory Structure


Key code selection process for streaming media playback

private void Playselectitem (String URL) {if (MPlayer = = null) Vplayerinit (FALSE); Mplayer.reset (); Uri uri = uri.parse (URL); try {mplayer.setdatasource (playservice.this, URI);//Set data source for streaming media mplayer.prepareasync (); The buffer that needs to be buffered cannot be used prepare is blocked, Prepareasync is asynchronous} catch (Exception e) {//Todo:handle exception}globalconstants.print_i (" Playservice "," playselectitem url = "+ URL);} private void Vplayerinit (Boolean ishwcodec) {try {mPlayer = new MediaPlayer (This.getapplicationcontext (), ishwcodec);// The object Mplayer.setonbufferingupdatelistener (this) that plays the stream media; Call Mplayer.setoncompletionlistener (this) when the network video stream buffer changes; Call Mplayer.setonpreparedlistener (this) after video playback is complete; Call Mplayer.setonerrorlistener (this) after the video preprocessing is complete; Called when an error occurs during an asynchronous operation call. For example, video Open failed Mplayer.setoninfolistener (this); Called when there is a warning or error message. Example: Start buffer, buffer end, download speed change} catch (Exception e) {//Todo:handle Exception}}
I also handled the call broadcast here.

/** * Processing Call broadcast *  * @author Administrator *  */class Phonestatereceiver extends Broadcastreceiver {@Overridepublic vo ID OnReceive (Context context, Intent Intent) {//TODO auto-generated method stubfinal String action = intent.getaction (); I F (Action.equalsignorecase (telephonymanager.action_phone_state_changed)) {final String state = Intent.getstringextra (telephonymanager.extra_state); Globalconstants.print_i ("Phonestatereceiver", "onreceive state =" + state); if (State.equalsignorecase ( telephonymanager.extra_state_ringing) | | State.equalsignorecase (Telephonymanager.extra_state_offhook)) {//Received extra_state_offhookpause ();} else if ( State.equalsignorecase (Telephonymanager.extra_state_idle)) {//Hang up will receive Extra_state_idlestartplay ();}}}
Monitor network status changes, if no network, will show a wifi icon

Class Connectionchangereceiver extends Broadcastreceiver {@Overridepublic void OnReceive (context context, Intent Intent {//TODO auto-generated method stubfinal String action = intent.getaction (); if (Action.equalsignorecase (connectivity_ Change_action)) {state wifistate = null; state mobilestate = null; Connectivitymanager cm = (Connectivitymanager) context.getsystemservice (context.connectivity_service); wifiState = Cm.getnetworkinfo (Connectivitymanager.type_wifi). GetState (); mobilestate = Cm.getnetworkinfo ( Connectivitymanager.type_mobile). GetState (); if (wifistate! = NULL && mobilestate! = null&& State.connected! = wifistate&& state.connected = = mobilestate) {//mobile network connection successfully toastutils.show ( Getapplicationcontext (), "connected to the Network"); mivicon.setvisibility (view.visible); mivwifi.setvisibility (View.GONE);}  else if (wifistate! = NULL && mobilestate! = null&& state.connected! = wifistate&& state.connected ! = mobilestate) {//Phone does not have any network toastutils.show (getapplicatIoncontext (), "Current network Unavailable"); mivicon.setvisibility (View.gone); mivwifi.setvisibility (view.visible);} else if (wifistate! = null && state.connected = = wifistate) {//wireless network connection succeeded Toastutils.show (Getapplicationcontext (), "Connected to the Network"); mivicon.setvisibility (view.visible); mivwifi.setvisibility (View.gone);}} }}
Other relevant code, interested in can download source

Code Download: http://download.csdn.net/detail/deng0zhaotai/7964051

If you want to compile under Eclipse you need to import all three projects, two are in the form of a library

Android Network Radio--using Vitamio decoding (ii)

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.