B4J Question Playing a video

Discussion in 'B4J Questions' started by techknight, Jul 13, 2018.

  1. techknight

    techknight Well-Known Member Licensed User

  2. techknight

    techknight Well-Known Member Licensed 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.

    Code:
    java.lang.ClassCastException: anywheresoftware.b4j.objects.PaneWrapper$ConcretePaneWrapper$NonResizePane cannot be cast to javafx.scene.layout.AnchorPane
     
  3. techknight

    techknight Well-Known Member Licensed User

    Ugh nevermind, it doesnt even support any codecs! Everything I own fails with media unsupported.
     
  4. stevel05

    stevel05 Expert Licensed User

    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.
     
  5. stevel05

    stevel05 Expert Licensed User

    I had to check it out, try this:

    Code:
    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
     
    techknight likes this.
  6. stevel05

    stevel05 Expert Licensed User

    And to move it as well :
    Code:
    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
     
    techknight likes this.
  7. techknight

    techknight Well-Known Member Licensed User

    I am going to give it a shot and see what happens. thanks for the help! Greatly appreciated.
     
  8. techknight

    techknight Well-Known Member Licensed 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.
     
  9. techknight

    techknight Well-Known Member Licensed User

    I just found the VLC plugin for B4J/Java and it works flawlessly. Probably going to stick with that.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice