So why can't we play videos in file assets directory?

straybullet

Member
Licensed User
Longtime User
I been seeing that if we package a video with our app we have to copy it to sd storage therefore taking up twice the space for 1 video to play it.

Is this information correct?

If so why, I use other platforms to create Android apps and they play the video in the apps asset directory (or don't require me to do anything special to).

Why does B4A require this step to play videos when we can load other files directly from the file assets?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
AFAIK the native VideoView cannot work with assets files.
It is possible to load a video file stored as a resource file. It will require some Reflection code.

I currently cannot provide the full solution. However if you like you can try to follow the answer here: android - I want to play a video from my assets or raw folder - Stack Overflow

To get the resource id you can use this code:
B4X:
Dim r As Reflector
Dim package As String
Dim id As Int
package = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
id = r.GetStaticField(package & ".R$raw", VideoNameWithoutExtension)
 
Upvote 0

straybullet

Member
Licensed User
Longtime User
Ok you may have hit the nail on the head.. You said native video view might be the issue. I have a feeling my other Android development system programmed their own video player.

Thanks for the quick reply, it's a shame there is no easy way to do this, because my search revealed numerous posts where people wanted to play the assets video file.

Thanks
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Its cause assets are zipped. You can move the video manually to sd and delete it when its done
 
Upvote 0

straybullet

Member
Licensed User
Longtime User
But so are the other assets I call from my APP if that's the case. Granted videos can be quite large, but coping form a zip to a SD can be slow as well.

Plus some devices do not have SD (cheap Chinese tablets for instance), and one of my newer phones doesn't have an SD call its ext_sd I do not know how this is handled, but I ran in to issues with the ext mount in others apps.

Thanks!

Its cause assets are zipped. You can move the video manually to sd and delete it when its done
 
Upvote 0

Highwinder

Active Member
Licensed User
Longtime User
But so are the other assets I call from my APP if that's the case. Granted videos can be quite large, but coping form a zip to a SD can be slow as well.

Plus some devices do not have SD (cheap Chinese tablets for instance), and one of my newer phones doesn't have an SD call its ext_sd I do not know how this is handled, but I ran in to issues with the ext mount in others apps.

Thanks!

Your app must test for writeable external storage on start up or refuse to run:

If File.ExternalWriteble = True Then
Msgbox("SD Card Installed","Woo Hoo!")
'Run your code
Else
Msgbox("No Writable External SD Card or Storage Found","Sux 2 B U")
ExitApplication
End If


Hope this helps.
 
Upvote 0
Top