How to play a video file in Gambas? [SOLVED]

Post

Posted
Rating:
#1 (In Topic #1011)
Regular
JumpyVB is in the usergroup ‘Regular’
I tried:

Code (gambas)

  1. Private myPlayer As New MediaPlayer As "Player"
  2. Public Sub Form_Open()
  3.   myPlayer.SetWindow(DrawingArea1)
  4.   myPlayer.URL = "/home/user/Videos/home_video_from_android_phone.mp4"
  5.   myPlayer.Play()
  6. Public Sub Form_Close()
  7.   myPlayer.Stop()
  8.   myPlayer.Close()
But I get error "Cannot set status"
Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
vuott is in the usergroup ‘Regular’
You have to change this line:

JumpyVB said

Code (gambas)

  1.   myPlayer.URL = "/home/user/Videos/home_video_from_android_phone.mp4"
  2.  

with:

Code (gambas)

  1.   myPlayer.URL = Media.URL("/home/user/Videos/home_video_from_android_phone.mp4")
  2.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
JumpyVB is in the usergroup ‘Regular’
Thank you vuott. It works.

Is there a way to play the video rotated 90 degrees?
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
Is there a way to play the video rotated 90 degrees?

You could rotate the video before playing it. Have a look here.
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
JumpyVB is in the usergroup ‘Regular’

cogier said

You could rotate the video before playing it. Have a look here.
Prerotating is not an option. I am making a simple video viewer to quickly view and delete unwanted home videos. Celluloid will play the video with the correct orientation. Also the orientation metadata is there - I checked with exiftool. Just need to figure out how to use gb.media correctly. The whole gstreamer tool chain seems very capable but also daunting.
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
vuott is in the usergroup ‘Regular’

JumpyVB said

Is there a way to play the video rotated 90 degrees?
At the moment the only way that works for me, to rotate a video, is to use the external resources of the GStreamer library with "Extern".
Check out this page, that I wrote, of the Gambas italian programmers Forum Wiki:

https://www.gambas-it.org/wiki/index.php/Riprodurre_un_video_ruotato_in_tempo_reale_con_la_funzione_esterna_%27%27gst_parse_launch(_)%27%27_di_GStreamer

Unfortunately I was unable to rotate a video using the resources of gb.media Component.  :|

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#7
Regular
vuott is in the usergroup ‘Regular’
Well, I got video rotation with gb.media resources, but   :? no audio output.
 
This is my test code by using "MediaPipeline" and "MediaControl" Classes of gb.media:

Code (gambas)

  1. Private Enum none = 0, clockwise, rotate_180, counterclockwise, horizontal_flip,
  2.              vertical_flip, upper_left_diagonal, upper_right_diagonal, automatic
  3.  
  4.  
  5. Public Sub Button1_Click()
  6.  
  7.   Dim pl As MediaPipeline
  8.   Dim src, bin, con, flp, snk As MediaControl
  9.  
  10.   pl = New MediaPipeline
  11.  
  12.   src = New MediaControl(pl, "filesrc")
  13.   src["location"] = "/path/of/videofile"
  14.    
  15. ' Sets necessary MediaControl (GStreamer plugins):
  16.   bin = New MediaControl(pl, "decodebin")
  17.   con = New MediaControl(pl, "videoconvert")
  18.   flp = New MediaControl(pl, "videoflip")
  19.   flp["method"] = clockwise
  20.   snk = New MediaControl(pl, "ximagesink")
  21.  
  22. ' Connects the set MediaControls:
  23.   src.LinkTo(bin)
  24.   bin.LinkLaterTo(con)
  25.   con.LinkTo(flp)
  26.   flp.LinkTo(snk)
  27.  
  28.   snk.SetWindow(DrawingArea1)
  29.  
  30.   pl.Play()
  31.  
  32.   Repeat
  33.     Wait 0.01
  34.   Until pl.Duration > 0.0
  35.  
  36. ' The elapsed time since the video started running:
  37.     Me.Title = "Tempus: " & Format(Time(0, 0, 0, pl.Position * 1000), "hh:nn:ss")
  38.     Wait 0.1
  39.   Until pl.Position >= pl.Duration
  40.  
  41.   pl.Close
  42.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#8
Regular
vuott is in the usergroup ‘Regular’
Well, this code lets you hear the audio as well:

Code (gambas)

  1. Private Enum none = 0, clockwise, rotate_180, counterclockwise, horizontal_flip,
  2.              vertical_flip, upper_left_diagonal, upper_right_diagonal, automatic
  3.  
  4.  
  5. Public Sub Button1_Click()
  6.  
  7.   Dim pl As MediaPipeline
  8.   Dim vsrc, vbin, vcon, vflp, vsnk, asrc, abin, acon, ares, asnk As MediaControl
  9.   Dim videofile As String
  10.  
  11.   videofile = "/path/of/videofile"
  12.  
  13.   pl = New MediaPipeline
  14.    
  15.   vsrc = New MediaControl(pl, "filesrc")
  16.   vsrc["location"] = videofile
  17.    
  18. ' Sets necessary MediaControl (GStreamer plugins):
  19.   vbin = New MediaControl(pl, "decodebin")
  20.   vcon = New MediaControl(pl, "videoconvert")
  21.   vflp = New MediaControl(pl, "videoflip")
  22.   vflp["method"] = clockwise
  23.   vsnk = New MediaControl(pl, "xvimagesink")
  24.  
  25.   abin = New MediaControl(pl, "decodebin")
  26.   acon = New MediaControl(pl, "audioconvert")
  27.   ares = New MediaControl(pl, "audioresample")
  28.   asnk = New MediaControl(pl, "autoaudiosink")
  29.  
  30. ' Connects the set MediaControls:
  31.   vsrc.LinkTo(vbin)
  32.   vbin.LinkLaterTo(vcon)
  33.   vcon.LinkTo(vflp)
  34.   vflp.LinkTo(vsnk)
  35.  
  36.   asrc = New MediaControl(pl, "filesrc")
  37.   asrc["location"] = videofile
  38.   asrc.LinkTo(abin)
  39.   abin.LinkLaterTo(acon)
  40.   acon.LinkTo(ares)
  41.   ares.LinkTo(asnk)
  42.  
  43.   vsnk.SetWindow(DrawingArea1)
  44.  
  45.   pl.Play()
  46.  
  47.   Repeat
  48.     Wait 0.01
  49.   Until pl.Duration > 0.0
  50.  
  51. ' The elapsed time since the video started running:
  52.     Me.Title = "Tempus: " & Format(Time(0, 0, 0, pl.Position * 1000), "hh:nn:ss")
  53.     Wait 0.1
  54.   Until pl.Position >= pl.Duration
  55.  
  56.   pl.Close
  57.    

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#9
Regular
JumpyVB is in the usergroup ‘Regular’
Thank you yeat again vuott. It works.
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
JumpyVB is in the usergroup ‘Regular’
I have observed that some home videos (recorded using an android phone) cannot be opened with Gambas gb.media in Linux Mint because GStreamer package is too old. The error message states: "Cannot set status". I have tested and can confirm that the problematic videos play fine with Gambas gb.media in EndeavourOS where GStreamer is up to date.
Online now: No Back to the top

Post

Posted
Rating:
#11
Guru
BruceSteers is in the usergroup ‘Guru’
 Well yes. GB.media is a gstreamer interface so it can only play what your gstreamer can.

Maybe you can install missing codecs. Like h264 etc (whatever format the unplayable files are)

Or upgrade your mint with the mintupdate tool.
Online now: No Back to the top
1 guest and 0 members have just viewed this.