Android Network Radio-decoding using Vitamio (2)
As mentioned above, the Android network radio uses Vitamio decoding (1) to play streaming media files, but only play once. Here, you can randomly click the menu on the left to play the video, however, Vitamio is still not very stable, and some Uris have expired and cannot be played. I downloaded a PC-based network radio for comparison. If it can be played on the PC, it can also be played here, some images on the Internet are used. First, let's look at the modified interface.
Because there is no network, only the Name is displayed.
Program directory structure
The key code selects a streaming media playback process
Private void playSelectItem (String url) {if (mPlayer = null) vplayerInit (false); mPlayer. reset (); Uri uri = Uri. parse (url); try {mPlayer. setDataSource (PlayService. this, uri); // sets the streaming media data source mPlayer. prepareAsync (); // The prepare cannot be used for buffering. The prepareAsync is asynchronous.} catch (Exception e) {// TODO: handle exception} GlobalConstants. print_ I (PlayService, playSelectItem url = + url);} private void vplayerInit (boolean isHWCo Dec) {try {mPlayer = new MediaPlayer (this. getApplicationContext (), isHWCodec); // stream media Playing Object mPlayer. setOnBufferingUpdateListener (this); // call mPlayer when the network video stream buffer changes. setOnCompletionListener (this); // call mPlayer after the video is played. setOnPreparedListener (this); // call mPlayer after video preprocessing. setOnErrorListener (this); // call when an error occurs during the Asynchronous Operation call process. For example, if the video fails to be opened, mPlayer. setOnInfoListener (this); // It is called when there is a warning or error message. Example: Start buffering, buffer end, download speed change} catch (Exception e) {// TODO: handle exception }}
The incoming call broadcast is also processed here.
/*** Process incoming call broadcast ** @ author Administrator **/class PhoneStateReceiver extends BroadcastReceiver {@ Overridepublic void onReceive (Context context, Intent intent) {// TODO Auto-generated method stubfinal String action = intent. getAction (); if (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) {// an EXTRA_STATE_OFFHOOKpause ();} else if (state. equalsIgnoreCase (TelephonyManager. EXTRA_STATE_IDLE) {// you will receive the EXTRA_STATE_IDLEstartPlay ();}}}}
The Network Status of the listener changes. If no network exists, a Wifi icon is displayed.
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_SERVI CE); 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) {// the network connection of the mobile phone is successful. 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) {// the mobile 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) {// ToastUtils is successfully CONNECTED to the wireless network. show (getApplicationContext (), connected to the network); mIvIcon. setVisibility (View. VISIBLE); mIvWifi. setVisibility (View. GONE );}}}}