Android Network Radio-decoding using Vitamio (2)

Source: Internet
Author: User

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 );}}}}
 

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.