Use Vitamio to create your Android universal player (5)-Online playback (playing Youku videos)

Source: Internet
Author: User

Preface

In order to ensure the progress of each Monday article, and because the new Vitamio version is not released, it is decided to delay some local playback functions (, video time, size, etc.), skip the section that directly writes the online playback part. From the introduction of Vitamio, we can see that it supports multiple network protocols such as http and m3u8. This chapter will compile an example of playing Youku videos. StatementWelcome to repost, but please keep the original source of the article :) blog Park: http://www.cnblogs.com farmer UNCLE: http://over140.cnblogs.com Series1. Use Vitamio to build your Android universal player (1) -- Preparation 2. Use Vitamio to build your Android universal player (2) -- gesture control brightness, volume, scaling 3. Use Vitamio to create your own Android universal player (3)-local playback (main interface, video List)

4. Use Vitamio to create your Android universal player (4)-local playback (quick search and data storage)BodyI. Objectives

1. officially named"Start video", Original intention:" Open-Source Video Player ", also has the simple meaning of" start playing video ", I hope you like it :)

2. Use the embedded Youku (3g.youku.com) method to directly play video files.

 

 

II. Implementation

FragmentOnline

Public class FragmentOnline extends FragmentBase {

Private WebView mWebView;

@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ){
View v = inflater. inflate (R. layout. fragment_online, container, false );
MWebView = (WebView) v. findViewById (R. id. webview );
MWebView. setScrollBarStyle (View. SCROLLBARS_OUTSIDE_OVERLAY );
MWebView. getSettings (). setJavaScriptEnabled (true );
MWebView. getSettings (). setPluginsEnabled (true );
MWebView. loadUrl ("http://3g.youku.com ");
MWebView. setWebViewClient (new WebViewClient (){
@ Override
Public void onPageFinished (WebView view, String url ){
};

/** Page Jump */
@ Override
Public boolean shouldOverrideUrlLoading (WebView view, String url ){
If (FileUtils. isVideoOrAudio (url )){
Intent intent = new Intent (getActivity (), VideoPlayerActivity. class );
Intent. putExtra ("path", url );
StartActivity (intent );
Return true;
}
Return false;
};
});

MWebView. setOnKeyListener (new OnKeyListener (){

@ Override
Public boolean onKey (View v, int keyCode, KeyEvent event ){
If (keyCode = KeyEvent. KEYCODE_BACK) & mWebView! = Null & mWebView. canGoBack ()){
MWebView. goBack ();
Return true;
}
Return false;
}
});
Return v;
}

}

Code Description:

Because 3g.youku.com is embedded, the page layout is very good, and it is very easy to get the playback address inside, just listen to the page Jump.

A). onKey handles the back event and returns to the previous page.

B) Pay attention to the shouldOverrideUrlLoading method of WebViewClinet. If the return value is true, the page will not be redirected. This will be improved later. If the playback fails, the browser will be used for flash playback.

C) The layout of fragment_online is a WebView control.

 

Iii. Download

Vitamio-Demo2012-6-15.zip

 

4. Warning

Video, books, and music are all subject to strict copyrights. It is important to consider how to avoid copyright issues. I consulted a friend. This document is acceptable. Generally, I decided to determine whether there is copyright or not to see if there is any advertisement removed. It happens that videos of 3g.youku.com do not carry any advertisement, directly Play the mp4 file.

 

V. Related Articles

Obtain the youku video address through Decompilation

How youku obtains video addresses

Youku video real address resolution

 

Vi. Vitamio and related

Vitamio: http://vov.io

VPlayer: http://vplayer.net (with more than 5 million users using Vitamio's most successful products)

 

EndThe m3u8 address has already been obtained. However, the current version of vitamio cannot play the resolved address, and the mp4 address is used directly, this problem has been fixed in later versions. You can check the effect of the new version of VPlayer. Although it is only a Demo so far, we are still striving to move towards a formal product. We hope to officially release the product to the App Store for users by the end of a series of articles. We also welcome you to give more suggestions ~~

 

 

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.