Android Question Video File in my App

Ajay Kakar

Member
Licensed User
Longtime User
Hi,

I need to play a video file from my server. I can create almost any kind of video file. I have tried multiple formats with the Videoview object. I always get the message "Cannot play the file" and the App almost crashes most of the time. Can anyone help me with the format.

Ajay
 

Ajay Kakar

Member
Licensed User
Longtime User
Thanks Sanjib. I have actually tried to play video files from my smartphone itself. I keep on getting so many videos on Whats App and other places. I just took a few of these video files and put them on my server. When I tried to play them from the Videoview in the APP they did not work. I have not been able to play a single video file from the Video view option. I have tried AVI, MPG, MP4, WMV and a few other formats. All give the same message - "Cannot play this file". I am actually stuck on two of my projects only for this one bit. B4 Android is a great tool and just wonderful to use. I wish someone could give me a way of playing a video file using the Videoview.

Ajay
 
Upvote 0

Ajay Kakar

Member
Licensed User
Longtime User
Not a problem at all. Please check out "http://www.bitein.com/fevicolad.mp4" This is a video clip that came to me on Whats App. It works when I open it on my browser. I also transferred it bluetooth to my phone and it works. But when i try to play it in my App, it says "Can't play this video".

Ajay
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
I am sorry .. made a mistake in the link It is "http://www.bitein.com/fevicolad.mpg". The extension is mpg and not mp4. The link works fine on a browser.

Ajay
Believe me, the Android native VideoView is very picky about the type of file it will play. Generally only "baseline profile .mp4" files are guaranteed to work (see table 2 in the link sanjibnanda posted above). Samsung mobiles seam to have better built-in media support, but they still won't play all files.
I'd recommend installing MXPlayer or some other media player of your choice and play the file by sending an intent instead.

Regards,
RandomCoder
 
Upvote 0

Ajay Kakar

Member
Licensed User
Longtime User
Where should I install the MX player ? The file is playing if I transfer it by bluetooth to the phone. How do I send an intent? Could you please elaborate.

Regards

Ajay
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Here's the code I use....
B4X:
' Place this code in the sub of your choice...
 
        ' Preferably display video with installed player else use VideoView (limited CODEC support on some devices)
        If VideoPlayerInstalled Then
            ' Use installed media player for better CODEC support
            ' Allow user to select they're preferred player
            Dim i As Intent
            i.Initialize(i.ACTION_VIEW, vvPath)
            i.SetType("video/rst")
            StartActivity(i)
        Else
            ' Use VideoView (only .mp4 baseline profile guaranteed to work!)
            vidResolution.Initialize
            vidResolution = RegExp.ExtractResolution(container.strResolution)
            StartActivity(Video_View) ' My VideoView is run as a service, and this is the call to start it.
        End If
And the code below checks to see if MXPlayer or VPlayer are installed...
B4X:
Private Sub VideoPlayerInstalled() As Boolean
    ' Check for installed apps capable of playing videos
    Dim Packages As PackageManager
    Dim i As Intent
    i.Initialize(i.ACTION_VIEW, "")
    i.SetType("video/*")
    For Each strName As String In Packages.QueryIntentActivities(i)
        ' Return True if any of these component names are installed
        If strName = "me.abitno.vplayer.t/me.abitno.vplayer.VideoActivity" OR _
                     "com.mxtech.videoplayer.ad/.ActivityScreen" Then Return True
    Next
    ' Return false if none of the above installed
    Return False
End Sub

Both MXPlayer and VPlayer are available via the Google Play Store. MXPlayer is very good and free! Of course you can choose to install any media player although it will need to support streaming for your purposes.

Regards,
RandomCoder
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…