B4A Library VitamioBundle

This library wraps the latest version of the VitamioBundle - that's currently version 4.2.0.
You can find more info on the VitamioBundle here:
https://github.com/yixia/VitamioBundle.

I'm not a user of this library, i just developed it for various other forum members.
So i'll post a basic code example and leave anyone that's interested to experiment for themselves to see what the library is capable of.

B4X:
#Region  Project Attributes 
   #ApplicationLabel: VitamioBundle4 example
   #VersionCode: 1
   #VersionName: 
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
   #AdditionalRes: C:\Users\foobar\Basic4Android\VitamioBundle-4-2-0\library_files\res, io.vov.vitamio
#End Region
#Region  Activity Attributes 
   #FullScreen: True
   #IncludeTitle: True
#End Region
'Activity module
Sub Process_Globals
End Sub
Sub Globals
   Dim VitamioMediaController1 As Vitamio_MediaController
   Dim VitamioVideoView1 As Vitamio_VideoView
End Sub
Sub Activity_Create(FirstTime As Boolean)
   '   take a look at the manifest editor to see the additional entry activity required in order to use VitamioBundle
  
   '   VitamioBundle version 4.2.0 uses the new #AdditionalRes project attribute
   
   '   check if the VitamioBundle core is installed
   '   if this is the first time that the installed application has been started then the core will NOT be installed
   '   otherwise the core should be already installed
  
   '   if the core is NOT installed then CheckVitamioLibs returns False and this Activity's Finish method is called by the library
   '   the core is then installed and this Activity will be restarted
   '   CheckVitamioLibs will now return True and you can proceed to use the library
  
   If VitamioVideoView1.CheckVitamioLibs Then
  
     VitamioVideoView1.Initialize("VitamioVideoView1")
     Activity.AddView(VitamioVideoView1, 0, 0, 100%x, 100%y)
    
     VitamioMediaController1.Initialize("VitamioMediaController1")
    
     VitamioVideoView1.SetMediaController(VitamioMediaController1)
     VitamioVideoView1.SetVideoQuality(VitamioVideoView1.VIDEO_QUALITY_HIGH)
    
     VitamioVideoView1.SetVideoPath("http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8")
     '   VitamioVideoView1.SetVideoPath(File.Combine(File.DirRootExternal, "test_video.mp4"))
    
   End If
  
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
'   events raised by Vitamio_MediaController
Sub VitamioMediaController1_Hidden
   Log("VitamioMediaController1_Hidden")
End Sub
Sub VitamioMediaController1_Shown
   Log("VitamioMediaController1_Shown")
End Sub
'   events raised by Vitamio_VideoView
Sub VitamioVideoView1_BitmapSubtitleUpdated(Bitmap1() As Byte, Width As Int, Height As Int)
  
End Sub
Sub VitamioVideoView1_Buffering(Percent As Int)
   '   Log("VitamioVideoView1_Buffering: "&Percent)   '   commented out to avoid excess logging
End Sub
Sub VitamioVideoView1_Complete
   Log("VitamioVideoView1_Complete")
End Sub
Sub VitamioVideoView1_Error(MEDIA_ERROR As Int) As Boolean
   '   this event Sub must return a Boolean value to indicate whether it has handled the error or not
   '   returning True will prevent the library from taking any action such as displaying an error message
   Log("VitamioVideoView1_Error")
  
   Return True
End Sub
Sub VitamioVideoView1_Info(What As Int, Extra As Int) As Boolean
   '   what does this event mean?
   '   what do the Int parameters represent?
  
   '   Log("VitamioVideoView1_Info")   '   commented out to avoid excess logging
   Return False    '   indicates that this Sub has NOT handled the event and that the library should handle it
End Sub
Sub VitamioVideoView1_Prepared
   Log("VitamioVideoView1_Prepared")
End Sub
Sub VitamioVideoView1_SeekComplete
  
End Sub
Sub VitamioVideoView1_TextSubtitleUpdated(SubText As String)
  
End Sub

Previous versions of the VitamioBundle have already been posted (by myself) on this thread:
http://www.b4x.com/android/forum/threads/video-view-fullscreen-and-on-top-on-ouya.31034/
The old links in that thread will no longer work - i've recently changed webhosts.

But the thread is full of useful info for anyone that's trying to use the VitamioBundle.
You'll read that the VitamioBundle is far from perfect and that it has a rather obscure licensing model that you as the developer will have to handle.

The library is a 8.7MB download - far too big to attach to this post.
So the library is currently available from my webspace at:
http://b4a.martinpearman.co.uk/vitamiobundle/
You'll also find the b4a demo project at the same link.
(VitamioBundle-4-2-0-library-files.zip and VitamioBundle-4-2-0-demo.zip are the latest versions).

Martin.
 
Last edited:

hookshy

Well-Known Member
Licensed User
Longtime User
You'll read that the VitamioBundle is far from perfect and that it has a rather obscure licensing model that you as the developer will have to handle.

What is the difference from Standard edition and Supreme edition ... Since we use your lib how do we know which version do we use .
Free or not ? and in what conditions ?


Relevant specifications:
1. Everyone except individual needs to buy the Vitamio license, such as: government agency, education,institution, association, enterprise etc.
2. The Vitamio standard edition only limited to individual developers is free.
3.Android and IOS must be separate for authorization.
4.The followings do not belong to the "Standard version"service.

* Problems caused by modifying or using non-original Vitamio programme code;
* Database running errors or crash due to directly manipulate database;
* Faults caused by installing plugins;
* System faults caused by server, virtual machine;
* Re-development or customization
5. Effective Date: 2013.2.17--2014.12.31
 

hookshy

Well-Known Member
Licensed User
Longtime User
I did tested your library on various android versions and phones... I must say it is indeed an nice workout ..it loads very fast and support various media formats.

The sample app I did staring on your example crashes all the time on tablet with kitkat ...does anyone tested on this android version ?
(unfortunately I could not catch the error on logs )

Is is possible to run radio streaming with a process with this lib , I did try it though and did not succeded ?
 

aignatd

Member
Licensed User
Longtime User

aignatd

Member
Licensed User
Longtime User
Dear Martin,

In your b4a Wrapper I added :

public void SetAutoBitrate(boolean Auto) {
MediaPlayer pMediaPlayer;
pMediaPlayer.setAdaptiveStream(Auto);
}

But why there is an error ?

Thank you


Dear Martin,

I've managed todo the compile b4a wrapper and the name of b4a wrapper still the same "vitamio_bundle".
When I use this library at basic4android there are an error like the following :

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. 0.00
Generating R file. 0.12
Compiling generated Java code. Error
B4A line: 117
pVideo.AddView(ViVideoView, 0, 0, 100%x, 100%y)
javac 1.6.0_38-ea
src\sindo\mncplaymedia\com\main.java:409: cannot access io.vov.vitamio.widget.VideoView
class file for io.vov.vitamio.widget.VideoView not found
mostCurrent._pvideo.AddView((android.view.View)(mostCurrent._vv4.getObject()),(int) (0),(int) (0),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (100),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (100),mostCurrent.activityBA));

Thank you
 

warwound

Expert
Licensed User
Longtime User
Look at the attached screenshot.

You need to export a .jar file containing the src folders from both VitamioBundle-4.2.0 and VitamioBundle-4.2.0-B4A.
The export must also contain the lib folder from either project - the lib folder is identical in each project.

So expand the project tree for each project, select the 2 src folders and a lib folder then right click the selected folders and Export.

When you generate the javadoc/xml file you only need to generate javadoc/xml for the VitamioBundle-4.2.0-B4A src folder - do not include the VitamioBundle-4.2.0 src folder.
So select just the VitamioBundle-4.2.0-B4A src folder then select menu Project > Generate Javadoc.
 

Attachments

  • eclipse_vitamio.jpg
    eclipse_vitamio.jpg
    64.7 KB · Views: 252

aignatd

Member
Licensed User
Longtime User
Look at the attached screenshot.

You need to export a .jar file containing the src folders from both VitamioBundle-4.2.0 and VitamioBundle-4.2.0-B4A.
The export must also contain the lib folder from either project - the lib folder is identical in each project.

So expand the project tree for each project, select the 2 src folders and a lib folder then right click the selected folders and Export.

When you generate the javadoc/xml file you only need to generate javadoc/xml for the VitamioBundle-4.2.0-B4A src folder - do not include the VitamioBundle-4.2.0 src folder.
So select just the VitamioBundle-4.2.0-B4A src folder then select menu Project > Generate Javadoc.


Dear Martin,

I've done what you said and there no more error.
Next, I add new function on b4a wrapper, like the following :

public MediaPlayer myMediaPlayer;

public void SetAutoBitrate(boolean adaptive) {
myMediaPlayer.setAdaptiveStream(adaptive);
}

then I create the .xml and .jar file (myVideoView.xml and myVideoView.jar)

When I use this library on my b4a project there an error, like the following :
java.lang.NullPointerException


Thank you.

(Sorry, I was just learning java programming)
 

warwound

Expert
Licensed User
Longtime User
You've created a property myMediaPlayer but not set it's value to anything - it is null.

The class io.vov.vitamio.widget.VideoView has a private property named mMediaPlayer which is the instance of the MediaPlayer that you require.
But mMediaPlayer is private and has no getter method - you cannot access it.

Try this:

  • Open the class io.vov.vitamio.widget.VideoView
  • Create a new method:
    B4X:
    public MediaPlayer getMediaPlayer(){
    	return mMediaPlayer;
    }
    You can place this new method anywhere in the class - i'd suggest before the getMetaEncoding() method to keep things sorted alphabetically.
    Here's the new method inserted between the existing isBuffering() and getMetaEncoding() methods:
    B4X:
    public boolean isBuffering() {
    	if (mMediaPlayer != null)
    		return mMediaPlayer.isBuffering();
    	return false;
    }
    
    public MediaPlayer getMediaPlayer(){
    	return mMediaPlayer;
    }
    
    public String getMetaEncoding() {
    	if (mMediaPlayer != null)
    		return mMediaPlayer.getMetaEncoding();
    	return null;
    }
  • Open the wrapper class uk.co.martinpearman.b4a.vitamio.widget
  • Remove your line that creates the myMediaPlayer property:
    B4X:
    public MediaPlayer myMediaPlayer; // delete this line
  • Create your new method, you can now access the MediaPlayer instance using the syntax getObject().getMediaPlayer():
    B4X:
    public void SetAdaptiveStream(boolean Adaptive){
    	getObject().getMediaPlayer().setAdaptiveStream(Adaptive);
    }

Now recompile and test...
 

salvadoro

Member
Licensed User
Longtime User
Hi Martin
Thank you very much for library.
It's a pity , but I have some problems. Video doesn't seem to resize to its view.It doesn't scale.
As you wrote here :
http://www.b4x.com/android/forum/th...n-and-on-top-on-ouya.31034/page-3#post-184486

There are some variants but I can't understand how to implement this in B4A through XML Layout Builder library:
http://stackoverflow.com/questions/17202603/vitamio-full-screen-videoview
http://stackoverflow.com/questions/16581273/vitamio-video-center-issue
https://github.com/yixia/VitamioBundle/tree/master/vitamio-sample/res/layout
https://bbs.vitamio.org/topics/43?locale=en

Update:
Solved this problem in this way
1. I have created an XML layout for Vitamio videoview:
B4X:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <io.vov.vitamio.widget.VideoView
        android:id="@+id/surface_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
     
</RelativeLayout>
2. Then I have loaded this layout to panel:
B4X:
pnlLayout.Initialize("")

    Activity.AddView(pnlLayout,150dip,0,100%x-150dip,100%y)
    xmlLayout.LoadXmlLayout(pnlLayout,"vitamio_layout")

    VitamioVideoView1.Initialize("VitamioVideoView1")
    VitamioVideoView1 = xmlLayout.GetView ("surface_view")

So video occupy only the size of panel , but you must preserve aspect ratio of video by checking its width and height.

Thanks
John

Hi Johnmcenroy,

Thanks for the ex. for resize the view, but how do you catch the error event, when i use xmlLayout can't catch this, only catch if dont use it.

Salvador.
 

aignatd

Member
Licensed User
Longtime User
You've created a property myMediaPlayer but not set it's value to anything - it is null.

The class io.vov.vitamio.widget.VideoView has a private property named mMediaPlayer which is the instance of the MediaPlayer that you require.
But mMediaPlayer is private and has no getter method - you cannot access it.

Try this:

  • Open the class io.vov.vitamio.widget.VideoView
  • Create a new method:
    B4X:
    public MediaPlayer getMediaPlayer(){
        return mMediaPlayer;
    }
    You can place this new method anywhere in the class - i'd suggest before the getMetaEncoding() method to keep things sorted alphabetically.
    Here's the new method inserted between the existing isBuffering() and getMetaEncoding() methods:
    B4X:
    public boolean isBuffering() {
        if (mMediaPlayer != null)
            return mMediaPlayer.isBuffering();
        return false;
    }
    
    public MediaPlayer getMediaPlayer(){
        return mMediaPlayer;
    }
    
    public String getMetaEncoding() {
        if (mMediaPlayer != null)
            return mMediaPlayer.getMetaEncoding();
        return null;
    }
  • Open the wrapper class uk.co.martinpearman.b4a.vitamio.widget
  • Remove your line that creates the myMediaPlayer property:
    B4X:
    public MediaPlayer myMediaPlayer; // delete this line
  • Create your new method, you can now access the MediaPlayer instance using the syntax getObject().getMediaPlayer():
    B4X:
    public void SetAdaptiveStream(boolean Adaptive){
        getObject().getMediaPlayer().setAdaptiveStream(Adaptive);
    }

Now recompile and test...


Dear Martin,

I've done your instructions like the following :

upload_2015-1-23_15-28-6.png


But the error still the same "java.lang.NullPointerException" (compiling b4a wrapper not showing an error).
if I see the statement "mMediaPlayer = new MediaPlayer(mContext, false)" this statement only running when I call "openvideo".

What is your suggestion ??

Thank you
 

Attachments

  • upload_2015-1-23_15-22-28.png
    upload_2015-1-23_15-22-28.png
    171.4 KB · Views: 231
  • upload_2015-1-23_15-22-42.png
    upload_2015-1-23_15-22-42.png
    171.4 KB · Views: 230
  • upload_2015-1-23_15-25-45.png
    upload_2015-1-23_15-25-45.png
    178.7 KB · Views: 228

warwound

Expert
Licensed User
Longtime User
if I see the statement "mMediaPlayer = new MediaPlayer(mContext, false)" this statement only running when I call "openvideo".

What is your suggestion ??

So the instance of MediaPlayer is only created after 'openvideo' is called - so you can only call SetAdaptiveStream after calling 'openvideo'.
There's no working around that .
 

aignatd

Member
Licensed User
Longtime User
So the instance of MediaPlayer is only created after 'openvideo' is called - so you can only call SetAdaptiveStream after calling 'openvideo'.
There's no working around that .

Dear Martin,

If I call your statement "GetMetaEncoding", I get the same error "java.lang.NullPointerException"
If i call after "openvideo" there no use, still error


Thank you





































































































































































GetMetaEncoding
 

warwound

Expert
Licensed User
Longtime User
Can you post a copy of the log that shows the error - a copy that shows line numbers in the java classes where the exception occurs?
 

scsjc

Well-Known Member
Licensed User
Longtime User
Hello,
is possible KillBackgroundProcesses("vitaminobundle") ??????
i try:

B4X:
    Dim m As ActivityManager
    m.KillBackgroundProcesses("io.vov.vitamio")

but don't work
because, i lost control from activity when the user (kill all activities) and the vitaminobundle continue working...
 

Asim A Baki

Active Member
Licensed User
Longtime User
is there anyway someone can build the current VitamioBundle-4.2.0-B4A wit the function
setFormat wrapped so we can use it with PixelFormat.RGBX_8888

Some people like me know nothing about using Eclipse, this is why I use B4A

Thanks
 

Asim A Baki

Active Member
Licensed User
Longtime User
is there anyway someone can build the current VitamioBundle-4.2.0-B4A wit the function
setFormat wrapped so we can use it with PixelFormat.RGBX_8888

Some people like me know nothing about using Eclipse, this is why I use B4A

Thanks

[SOLVED]
After some digging, I found a simple solution, setVideoChroma(0) in the initialization as the code below that fixed the pixelated picture issue

B4X:
    VitamioVideoView1.Initialize("VitamioVideoView1")
   
    If VitamioVideoView1.CheckVitamioLibs Then
   

        Activity.AddView(VitamioVideoView1, 0,0,100%x,100%y)
       
        'VitamioMediaController1.Initialize("VitamioMediaController1")
        VitamioVideoView1.SetVideoChroma(0)
        VitamioVideoView1.SetBufferSize (20000)
        VitamioVideoView1.SetVideoQuality(VitamioVideoView1.VIDEO_QUALITY_MEDIUM )

    End If

I hope this could save sombody's time
 
Top