Android uses Vitamio to build its own universal player (10)--local playback (thumbnail, video information, video scanning service) _android

Source: Internet
Author: User
Tags svn

Objective

Vitamio is our team's good faith, in addition to the Vplayer to make the best Android player, but also to the Vitamio to create the best player components Android. The new release of the Beta SDK although there are some problems, but already have a high scalability, convenience and many built-in practical functions, follow-up articles will continue to dig and introduce the use of Vitamio details and methods. This chapter will provide video information such as thumbnails, video sizes, and the use of Vitamio built-in ContentProvider and file scanning services.

Attention

This chapter ContentProvider is no longer available in the SDK published in 2012-8-31, and subsequent articles update usage.

Series

1. Android uses Vitamio to build its own universal player (1)--ready

2, Android uses Vitamio to build its own universal player (2)--gesture control brightness, volume, zoom

3, Android use Vitamio to build their own universal player (3)--local playback (main interface, video list)

4, Android use Vitamio to build their own universal player (4)--Local playback (fast search, data storage)

5, Android use Vitamio to build their own universal player (5)--Play online (play cool video)

6. Android uses Vitamio to build its own universal player (6)--Play Online (playlist)

7, Android use Vitamio to build their own universal player (7)--Play Online (download video)

8, Android uses Vitamio to build its own universal player (8)--Detail optimization

9. Android uses Vitamio to build its own universal player (9)--online playback (online TV)

Body

I. Objectives

1.1 Get video thumbnails, etc.

Before the article is their own scan to obtain the video file information, here to add access to video thumbnails, video broadband code, to participate in the article 2.1 parts.

1.2 Call the Vitamio Scan service

The new SDK has a built-in video scanning service that provides all the data needed for local video playback.

Second, realize

2.1 Own scan to get video thumbnail, video width high

 public static arraylist<pfile> Batchbuildthumbnail (Final ctx, final arraylist<file> files) {Arrayl

 ist<pfile> result = new arraylist<pfile> ();
 for (File f:files) {PFile pf = new PFile (); try {if (f.exists () && f.canread ()) {//Remove one frame image of video Bitmap Bitmap = Thumbnailutils.createvideothumbnail (CTX, F.G
 Etabsolutepath (), Video.Thumbnails.MINI_KIND); if (bitmap = null) {//thumbnail creation failed bitmap = Bitmap.createbitmap (Thumbnailutils.target_size_mini_thumbnail_width, THUMBNAIL
 Utils.target_size_mini_thumbnail_height, Bitmap.Config.RGB_565);
 LOG.E (TAG, "Batchbuildthumbnail createbitmap faild:" + F.getabsolutepath ());
 } pf.width = Bitmap.getwidth ();

 Pf.height = Bitmap.getheight (); Thumbnail bitmap = Thumbnailutils.extractthumbnail (Bitmap, Thumbnailutils.diptopx (CTX, Thumbnailutils.target_size_micro _thumbnail_width), Thumbnailutils.diptopx (CTX, Thumbnailutils.target_size_micro_thumbnail_height),
 Thumbnailutils.options_recycle_input); if (bitmap != null) {file Thum = new file (F.getparent (), f.getname () + ". jpg");
 Pf.thumb = Thum.getabsolutepath ();
 Thum.createnewfile ();
 FileOutputStream IStream = new FileOutputStream (Thum);
 Bitmap.compress (Bitmap.CompressFormat.JPEG, IStream);
 Istream.close ();
 } if (bitmap!= null) bitmap.recycle ();
 The catch (Exception e) {log.e (TAG, E);
 Continue
 Finally {Result.add (PF);

 } return result; 
 }

Code Description:

a). The size of the thumbnail can be adjusted, you can look at this default size.

b). The code here is a thumbnail. The default exists under the current video path, and the filename and video name add a jpg suffix.

2.2 Calling Vitamio's video scanning service

2.2.1 Androidmanifest.xml

 <receiver android:name= "Io.vov.vitamio.MediaScannerReceiver" > <intent-filter> <action android:name= "Android.intent.action.BOOT_COMPLETED"/> </intent-filter> <intent-filter> <action android:name= " Android.intent.action.MEDIA_MOUNTED "/> <data android:scheme=" file "/> </intent-filter> < intent-filter> <action android:name= "Com.yixia.vitamio.action.MEDIA_SCANNER_SCAN_FILE"/> <action
 Android:name= "Com.yixia.vitamio.action.MEDIA_SCANNER_SCAN_DIRECTORY"/> <data android:scheme= "file"/> </intent-filter> </receiver> <service android:name= "Io.vov.vitamio.MediaScannerService" Android: Exported= "false" > <intent-filter> <action android:name= "Io.vov.vitamio.IMediaScannerService"/> < /intent-filter> </service> <service android:name= "Io.vov.vitamio.VitamioService" android:exported= " False "> <intent-filter> <action android:name=" Io.vov.vitamIo. Ivitamioservice "/> </intent-filter> </service>

Code Description:

It is primarily the registration of Mediascannerservice services and mediascannerreceiver listeners.

2.2.2 Boot Scan Service (mainfragmentactivity)

 if (!io.vov.vitamio.libschecker.checkvitamiolibs (this, GetClass (). GetName (), R.string.init_decoders, R.raw.libarm) ) return
 ;

 Opreference pref = new Opreference (this);
 First run, scan SD card
 if (Pref.getboolean (Pref_key_first, True)) {
 getapplicationcontext (). StartService (New Intent ( Getapplicationcontext (), Mediascannerservice.class). Putextra (Mediascannerservice.extra_directory, Environment.getexternalstoragedirectory (). GetAbsolutePath ());
 Pref.putbooleanandcommit (Pref_key_first, false);
 

Code Description:

The Opreference object encapsulates the sharedpreferences storage data. This determines whether to start the application for the first time, and then start the video scanning service.

   2.2.3   Get Data ( fragmentfile )

 private static final string[] Projection_media = new string[] {video.media._id, VIDEO.M Edia. TITLE, Video.Media.TITLE_KEY, Video.Media.SIZE, Video.Media.DURATION, Video.Media.DATA, Video.Media.WIDTH,
 Video.Media.HEIGHT};
 
 private static final String Order_media_title = Video.Media.TITLE_KEY + "COLLATE nocase ASC";
 @Override public loader<cursor> oncreateloader (int arg0, Bundle arg1) {log.e (TAG, "Oncreateloader");
 return new Cursorloader (Mparent, Video.Media.CONTENT_URI, projection_media, NULL, NULL, order_media_title); @Override public void onloadfinished (loader<cursor> arg0, Cursor newcursor) {log.e (TAG, "onloadfinished" + NE
 Wcursor.getcount ());
 Madapter.swapcursor (Newcursor);
 Mlistview.setselectionfromtop (Mvisiableposition, mvisiabletop);
 @Override public void Onloaderreset (loader<cursor> arg0) {log.e (TAG, "Onloaderreset");
 Madapter.swapcursor (NULL); }

Code Description:

a). Fragmentfile inherited Loadercallbacks<cursor>, the relevant information you can search.

b). Where Video.Media.DATA is the path to the video.

c). How to take thumbnails:

Video.Thumbnails.getThumbnail (Ctx.getapplicationcontext (), Ctx.getcontentresolver (), _id, Video.Thumbnails.MICRO_ KIND, NULL)

This "_id" is video.media._id, thumbnails exist in SD, you can add some cache processing.

III. Matters of note

3.1 Before starting the video service scan, you need to ensure that the decoding library has been decompressed, that is, the calling code: Libschecker.checkvitamiolibs

3.2 Make sure that Mediascannerservice is in a process with the current application, that is, do not specify its android:process, otherwise the video scanning service cannot be used.

3.3 There is still a problem getting the scan to complete the broadcast reception, which is not known whether the scan has been completed. The current approach is to determine whether the service is available 5 seconds after each data change, without which means the scan has been completed. See method Mediascannerreceiver.isservicerunning.

Decoding libraries

https://bitbucket.org/ABitNo/ffmpegandroid

http://vplayer.net at the bottom of the homepage has been given a link, note that the code does not real-time synchronization, the need for friends can refer to.

Four, OPlayer

4.1 Download

Please go to #taocode (SVN):

Project Address: Http://code.taobao.org/p/oplayer

SVN address: http://code.taobao.org/svn/oplayer/

4.2 Update

a). Move the display SD remaining capacity to the bottom and display the icon that is being loaded on the left.

b). Retain the original fragmentfile as Fragmentfildold, the new version has been switched to the use of Vitamio built-in video scanning services.

c). Replace adapter as CursorAdapter, and update A-Z feature to participate in code updates.

D. Preference is added to store general settings data, such as whether to start first.

V. Supplementary notes

has been highlighted in the SDK release release, and here's a second emphasis:

5.1 Vitamio related items cannot exist on the same device at the same time, and cannot coexist with Vplayer, a known bug that will be resolved in the next release.

The 5.2 Vitamio sample project needs to be compiled above the API Level14, but the minimum version can support more than 7 (android:minsdkversion= "7"). can be removed values-v11 and values-v14 two folders, Vitamio in the current project use is compatible with Android2.1 version, the lower has not tried, we can try.

5.3 Network video can not play, very slow may have the following several reasons:

a). Your speed is not good.

b). Video server is not working, or its bandwidth is not enough

c). May be the problem of playback components, we are still improving, increase the network playback this part of the optimization, thanks for understanding and support.

When this happens, please send us your video test address and attach a brief description. (vplayer@yixia.com)

5.4 has been stuck in the initial solution of the code packet Interface problem

This usually happens for only one reason: there are other Vitamio related items on your device, reference 5.1.

End

  This article cost me at least 10 hours, last night until 2, in order to solve the user's heart of doubt, and ultimately better service to users. In the case of lack of documentation in this way to share the use of methods and techniques and points of attention, but also please understand.

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.