B4J Question Playing a video

techknight

Well-Known Member
Licensed User
Longtime User
I found a MediaView library but it wont let me play it in a Pane, and I think its been abandoned as the thread has not had any activity from its author in years.

B4X:
java.lang.ClassCastException: anywheresoftware.b4j.objects.PaneWrapper$ConcretePaneWrapper$NonResizePane cannot be cast to javafx.scene.layout.AnchorPane
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Ugh nevermind, it doesnt even support any codecs! Everything I own fails with media unsupported.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I dont see any scaling options for the mp object.
I haven't tried it, but you should be able to set the size on the MediaView object from the example, try casting it to a node and set the prefHeight and prefWidth.

If it doesn't work I can take a look at it on Monday.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I had to check it out, try this:

B4X:
    Dim mp As MediaPlayer
    Dim jo,mv As JavaObject
    mp.Initialize("mp",File.geturi(File.DirAssets,"Vid1.mp4"))
    'mp.Initialize("mp",File.GetUri(File.DirAssets,"darling.mp4"))
    mv=jo.InitializeNewInstance("javafx.scene.media.MediaView",Array As Object(mp))
    MainForm.RootPane.AddNode(mv,0,0,MainForm.WindowWidth,MainForm.Height)
    mv.RunMethod("setFitWidth",Array(300.0)) 'Requires a double value, hence the decimal
    mv.RunMethod("setFitHeight",Array(200.0))
    mp.Play

More info and options here: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/media/MediaView.html
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
And to move it as well :
B4X:
    Dim mp As MediaPlayer
    Dim jo,mv As JavaObject
    mp.Initialize("mp",File.geturi(File.DirAssets,"Vid1.mp4"))
    'mp.Initialize("mp",File.GetUri(File.DirAssets,"darling.mp4"))
    mv=jo.InitializeNewInstance("javafx.scene.media.MediaView",Array As Object(mp))
    MainForm.RootPane.AddNode(mv,0,0,MainForm.WindowWidth,MainForm.Height)
    mv.RunMethod("setX",Array(100.0))
    mv.RunMethod("setY",Array(100.0))
    mv.RunMethod("setFitWidth",Array(300.0))
    mv.RunMethod("setFitHeight",Array(200.0))
    mp.Play
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
It worked.

I tried the same thing yesterday but kept getting a not matched error. But then I suddenly realized I had to use the decimal point.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I just found the VLC plugin for B4J/Java and it works flawlessly. Probably going to stick with that.
 
Upvote 0
Top