Mobile phone Audio and Video 8-video player advanced features (1), 8-advanced features

Source: Internet
Author: User

Mobile phone Audio and Video 8-video player advanced features (1), 8-advanced features
1. enable other software to enable self-written players

1. Add the following intent in the function list file

<intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><data android:scheme="rtsp" /> </intent-filter> <intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><data android:mimeType="video/*" /><data android:mimeType="application/sdp" /> </intent-filter> <intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><data android:scheme="http" /><data android:mimeType="video/mp4" /><data android:mimeType="video/3gp" /><data android:mimeType="video/3gpp" /><data android:mimeType="video/3gpp2" /> </intent-filter>

2. file or image browser // 1. enable all playing of the system-implicit Intent intent Intent = new intent (); Intent. setDataAndType (Uri. parse ("video playback address"), "video/*"); context. startActivity (intent );

3. The video player will be started and played.

Uri = getIntent (). getData (); // folder, image browser, QQ space

4. Set the playback address

videoview.setVideoURI(uri);

2. the cache progress can be displayed during online video playback.

1 _ support for buffering of online videos

/*** Determine whether it is a network resource * @ param uri * @ return */public boolean isNetUri (Uri uri) {boolean result = false; if (uri! = Null) {if (uri. toString (). contains ("http") | uri. toString (). contains ("RTSP") | uri. toString (). contains ("MMS") {result = true;} else {result = false ;}} return result ;}

2 _ support displaying cache progress when playing online videos

// Update the cache progress if (isNetUri) {// only network resources have cache effect int buffer = videoview. getBufferPercentage (); // 0 ~ 100int totalBuffer = buffer * seekbarVideo. getMax (); int secondaryProgress = totalBuffer/100; seekbarVideo. setSecondaryProgress (secondaryProgress);} else {// The local video has no buffer effect seekbarVideo. setSecondaryProgress (0 );}
3. Monitor card and prompt & listen for dragging

1 _ monitoring card and prompt

<! -- Card effect --> <? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: id = "@ + id/ll_videobuffer" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_centerInParent = "true" android: background = "#33000000" android: visibility = "gone" android: gravity = "center" android: orientation = "horizontal"> <ProgressBar android: layout_width = "30dp" android: layout_height = "30dp"/> <TextView android: id = "@ + id/TV _netspeed" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_marginLeft = "5dp" android: text = "network speed: 20kb/s" android: textColor = "@ android: color/white" android: textSize = "18sp"/> </LinearLayout>

Code
Define the monitoring card method and listener completion method in VideoView

// Sets videoview for the invigilator card 2.3 and later versions. setOnInfoListener (new OnInfoListener () {@ Override public boolean onInfo (MediaPlayer mp, int what, int extra) {switch (what) {case MediaPlayer. MEDIA_INFO_BUFFERING_START: // callback when the card is being dragged or when the card is being dragged. // Toast. makeText (getApplicationContext (), "the video is stuck", 1 ). show (); player_buffer.setVisibility (View. VISIBLE); isBuffing = true; break; case MediaPlayer. MEDIA_INFO_BUFFERING_END: // call back when the card is stuck and when the drag card ends. // Toast. makeText (getApplicationContext (), "the video is not blocked", 1 ). show (); player_buffer.setVisibility (View. GONE); isBuffing = false; break;} return true ;}});

2 _ custom monitoring card

// Monitoring card if (! IsUseSystem) {if (videoview. isPlaying () {int buffer = currentPosition-precurrentPosition; if (buffer <500) {// The video is stuck with ll_buffer.setVisibility (View. VISIBLE);} else {// The video is not stuck with ll_buffer.setVisibility (View. GONE) ;}} else {ll_buffer.setVisibility (View. GONE );}}

3_listener dragged

// Complete videoview by dragging the settings. setOnSeekCompleteListener (new OnSeekCompleteListener () {@ Override public void onSeekComplete (MediaPlayer mp) {if (isBuffing) {// TODO Auto-generated method stubplayer_buffer.setVisibility (View. GONE );}}
});

Baidu search: android gets the current network speed
Http://www.2cto.com/kf/201412/358191.html

/*** Get the current network speed * @ paramcontext * @ return */public String getNetSpeed (Context context) {long nowTotalRxBytes = TrafficStats. getUidRxBytes (context. getApplicationInfo (). uid) = TrafficStats. UNSUPPORTED? 0 :( TrafficStats. getTotalRxBytes ()/1024); // convert to KB; long nowTimeStamp = System. currentTimeMillis (); longspeed = (response-lastTotalRxBytes) * 1000/(nowTimeStamp-lastTimeStamp); // millisecond conversion lastTimeStamp = nowTimeStamp; duration = duration; String speedStr = String. valueOf (speed) + "kb/s"; return speedStr ;}

  

  

  

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.