vitamio is the sincerity of our team,In addition to making vplayer the best player for android,Also make vitamio the best player component for android.Although the new version of the internal beta SDK has some problems,But it already has high scalability, convenience, and many built-in practical functions.Subsequent articles will continue to dig deep and introduce the use details and methods of vitimio.This chapter will provide video information such as displaying thumbnails, video size, etc.And introduces the use of the built-in contentprovider and file scanning service of vitimio.


The contentprovider in this chapter is no longer available in the SDK released on August 31, 2012.Future articles will update usage.


1,Android uses vitamio to build your own universal player (1)-ready

2,Android uses vitamio to create your own universal player (2)-gesture control brightness, volume, zoom

3.Android uses vitamio to create its own universal player (3)-local playback (main interface, video list)

4.Android uses vitamio to create its own universal player (4)-local playback (quick search, data storage)

5.Android uses vitamio to build your own universal player (5)-online playback (play Youku video)

6.Android uses vitamio to create your own universal player (6)-online play (playlist)

7.Android uses vitamio to create your own universal player (7)-online play (download video)

8,Android uses vitamio to build its own universal player (8)-details optimization

9,Android uses vitamio to create your own universal player (9)-online playback (online TV)


I. Goal

1.1 Get video thumbnails, etc.

The previous articles are all video file information obtained by scanning.Here is the code to get video thumbnails and video broadband.Take part in Article 2.1.

1.2 Invoke vitamio's scanning service

The new SDK has a video scanning service built in,Provides all the data needed for local video playback.


2.1 Scan for video thumbnails, video width and height by yourself

public static arraylist<pfile>batchbuildthumbnail (final context ctx, final arraylist<file>files) {
 arraylist<pfile>result=new arraylist<pfile>();
 for (file f:files) {
 pfile pf=new pfile ();
 try {
 if (f.exists ()&&f.canread ()) {
 //Remove a frame of video
 bitmap bitmap=thumbnailutils.createvideothumbnail (ctx, f.getabsolutepath (), video.thumbnails.mini_kind);
 if (bitmap == null) {
 //Thumbnail creation failed
 bitmap=bitmap.createbitmap (thumbnailutils.target_size_mini_thumbnail_width, thumbnailutils.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 ();
 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, 85, istream);
 istream.close ();
 if (bitmap!=null)
 bitmap.recycle ();
 } catch (exception e) {
 log.e (tag, e);
 } 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 that the thumbnail is stored under the current video path by default,And the file name is the same as the video name,Added a suffix of jpg.

2.2 Invoke vitamio's video scanning service


<receiver android:name="io.vov.vitamio.mediascannerreceiver">
 <action android:name="android.intent.action.boot_completed" />
 <action android:name="android.intent.action.media_mounted" />
 <data android:scheme="file" />
 <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" />
 <action android:name="io.vov.vitamio.imediascannerservice" />
 <action android:name="io.vov.vitamio.ivitamioservice" />

Code description:

Mainly the registration of the mediascannerservice service and the mediascannerreceiver listener.

2.2.2 Start the scanning service (mainfragmentactivity)

if (! io.vov.vitamio.libschecker.checkvitamiolibs (this, getclass (). getname (), r.string.init_decoders, r.raw.libarm))
 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 sharedpreferences to store data.Here's whether to start the application for the first time,If yes, start the video scanning service.

2.2.3 Get data (fragmentfile)

private static final string [] projection_media=new string [] {video.media._id, video.media.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";
 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);
 public void onloadfinished (loader<cursor>arg0, cursor newcursor) {
 log.e (tag, "onloadfinished" + newcursor.getcount ());
 madapter.swapcursor (newcursor);
 mlistview.setselectionfromtop (mvisiableposition, mvisiabletop);
 public void onloaderreset (loader<cursor>arg0) {
 log.e (tag, "onloaderreset");
 madapter.swapcursor (null);

Code description:

a) .fragmentfile inherits loadercallbacks, you can search for related information.

b). Where video.media.data stores the path of the video.

c). Method for taking thumbnails:

video.thumbnails.getthumbnail (ctx.getapplicationcontext (), ctx.getcontentresolver (), _id, video.thumbnails.micro_kind, null)

This "_id" is video.media._id, the thumbnail is stored in SD, you can add some cache processing.

Third, matters needing attention

3.1 Before starting the video service scan,You need to make sure that the decoding library has been decompressed.That is the calling code:libschecker.checkvitamiolibs

3.2 Make sure 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 At present, there is still a problem in receiving broadcasts and completing broadcast reception.That is, it is impossible to know whether the scan has been completed.The current method is to determine whether the service exists 5 seconds after each data change, and it means that the scan is complete.See method mediascannerreceiver.isservicerunning.

Decoding Library


A link has been given at the bottom of the homepage of http://vplayer.net,Note that the code is not synchronized in real time,Friends in need can refer to it.

Fourth, 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 remaining capacity of SD to the bottom,It also shows the loading icon on its left.

b). Keep the original fragmentfile as fragmentfildold. The new version has been switched to use the built-in video scanning service of vitalio.

c). Change the adapter to cursoradapter, update the functions of a-z, and participate in the code update.

d). Added preference for storing general setting data,For example, whether to start for the first time.

V. Supplementary notes

A lot has been emphasized in the SDK release,Here again to emphasize:

5.1vitamio related items cannot exist on the same device at the same time,It also cannot coexist with vplayer. This is a known bug and will be fixed in the next version.

5.2vitamio example project needs to be compiled above api level14,But the minimum version can support 7 or more (android:minsdkversion="7"). You can delete the values-v11 and values-v14 folders,vitamio is compatible with android 2.1 and above in the current project.Lower haven't tried,You can try it.

5.3 There are several reasons why the network video cannot be played and is very slow:

a). Your internet speed is not working

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

c). May be a problem with the playback component,We are continuously improving,Increase the optimization of this part of network playback,Thanks for understanding and support.

When this happens,If convenient, please send us the video test address,And attach a brief description.([email protected])

5.4 The problem that has been stuck in the initialization decoding package interface

This usually happens,There is only one reason:there are other vitamio related items on your device,Refer to 5.1.


  • Previous ASPNET Core 10 implements mail sending function
  • Next SQL Server trigger and transaction usage examples