B4J Question Video Player size

Tayfur

Well-Known Member
Licensed User
Longtime User
I used @stevel05 's sample in my code.

But it not resize
https://www.b4x.com/android/forum/threads/playing-a-video.95095/

i addded full sample in attahment.

Or;
if you have more good player lib.; plase share to us.


B4X:
Private Sub Base_Resize (Width As Double, Height As Double)
    Log("Base_Resize ")
    ScrollPaneX.PrefWidth=Width
    ScrollPaneX.PrefHeight=Height

    Redraw
    CallSub3(mCallBack,mEventName & "_Resize",Width,Height)
End Sub

Private Sub Redraw
    'If Ratio<1.1 And Ratio>0.9 Then Ratio=1
    
    
    If Video.IsInitialized Then
        Log("Ratio:"&Ratio)
        ScrollPaneX.InnerNode.PrefHeight=ScrollPaneX.PrefHeight*Ratio
        ScrollPaneX.InnerNode.PrefWidth=ScrollPaneX.PrefWidth*Ratio
        Real_image_Width=ScrollPaneX.InnerNode.PrefWidth
        Real_image_Height=ScrollPaneX.InnerNode.PrefHeight
        Log("innernodesize:"&Real_image_Width&":"&Real_image_Height)
        Video.Pause
        'Log("video Redraw"&Real_image_Width&"-"&Real_image_Height)
        Dim jo,mv As JavaObject
        mv=jo.InitializeNewInstance("javafx.scene.media.MediaView",Array As Object(Video))
        Log("V.size:"&(Real_image_Width)&" - "&(Real_image_Height))
        mv.RunMethod("setX",Array(0.0))
        mv.RunMethod("setY",Array(0.0))
        mv.RunMethod("setFitWidth",Array(Real_image_Width))
        mv.RunMethod("setFitHeight",Array(Real_image_Height))
        Video.Play
    Else
        ScrollPaneX.InnerNode.PrefHeight=Real_image_Height*Ratio
        ScrollPaneX.InnerNode.PrefWidth=Real_image_Width*Ratio
        imageViewX.PrefWidth=Real_image_Width*Ratio
        imageViewX.PrefHeight=Real_image_Height*Ratio
    End If
End Sub
 

Attachments

  • test.zip
    415.9 KB · Views: 183

stevel05

Expert
Licensed User
Longtime User
I can't test your example, there is no video to load in it.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I don't have one to hand, it would be simpler and easier to help you if I did not have to search for one.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You were creating multiple Mediaviews each time the screen was resized, Create one as a Global variable and change the size of that.

You also need to remove the mediaview before you open a file, if it is already displayed.
 

Attachments

  • mv1.zip
    415.9 KB · Views: 219
Last edited:
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
You were creating multiple Mediaviews each time the screen was resized, Create one as a Global variable and change the size of that.

You also need to remove the mediaview before you open a file, if it is already displayed.

I looked your code :)


Thank you for support.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Here is what I use:

B4X:
Sub PlayVideo(SubDir As String, filename As String, repeat As Boolean)
    Dim mp As MediaPlayer
    Dim jo,mv As JavaObject
    mp.Initialize("mp",File.geturi(SubDir,filename))
    mv=jo.InitializeNewInstance("javafx.scene.media.MediaView",Array As Object(mp))
    pnlContent.AddNode(mv,0,0,OutputWindow.Width,OutputWindow.Height)
    mv.RunMethod("setPreserveRatio", Array(False))
    mv.RunMethod("setX",Array(0.0))
    mv.RunMethod("setY",Array(0.0))
    mv.RunMethod("setFitWidth",Array(pnlContent.Width))
    mv.RunMethod("setFitHeight",Array(pnlContent.Height))
    If repeat = True Then
        mp.CycleCount = -1
    End If
    mp.Play
End Sub

This works without needing the "mediaview" library, just mediaplayer. Of course you need to tweak the control names to yours.

Or, if you want to use the mediaview library floating around here, you could use this:

B4X:
Sub PlayVideo2(SubDir As String, Filename As String, repeat As Boolean)
    Dim mp As MediaPlayer
    Dim mv As MediaView
    mp.Initialize("mp",File.geturi(SubDir,Filename))
    mv.init("mv",pnlContent,mp)
    mv.PreserveRatio = False
    mv.FitHeight = pnlContent.Height
    mv.FitWidth = pnlContent.Width
    mv.X = 0.0
    mv.Y = 0.0
    If repeat = True Then
        mp.CycleCount = -1
    Else
        mp.CycleCount = 1
    End If
    mp.Play
End Sub

There is a bug in that library which I had to decompile the library, fix it, and recompile it. I will probably attach it somewhere soon.

But, I am not resizing the video on the fly. To do that, MediaView would have to be declared globally, and not re-initting it.
 
Upvote 0
Top