MediaView questions

Post

Posted
Rating:
#1 (In Topic #1415)
Regular
rj71 is in the usergroup ‘Regular’
 Does MediaView allow seek or resume at a specific time in a video? I'm using buttons instead of the built-in mediaview controls…simple play, pause and stop. If I hit my pause button (mediaview.pause), works just fine but if I hit my Play button (mediaview.play) it starts the video from the beginning instead of where it paused. I also have a timer that grabs the mediaview.position and stuffs it in a valuebox, was hoping to save that info and then be able to come back later and resume at that position. I guess I need to somehow take that saved position and resume after a pause but I'm not sure how.

On a side note, what is the difference between MediaView and MediaPlayer? Seems like MediaPlayer is more robust according to the wiki. Maybe I should be using that for seek/resume?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
Mediaview.Pause does pause and resume where it left off when using MediaView.Play.

Only if you use MediaView.Stop will it not resume and start from the beginning
(Or maybe if you set MediaView.URL again in the play method)

The following code works exactly as expected for me.

(Post your code so we can see the problem)

Code (gambas)

  1.  
  2. Public Sub btnPlay_Click()
  3.  
  4.   MediaView1.Play  ' Plays or resumes at MediaView.Position
  5.  
  6.  
  7. Public Sub btnPause_Click()
  8.  
  9.   MediaView1.Pause ' stops play and MediaView.Position pauses where it is.
  10.  
  11.  
  12. Public Sub btnStop_Click()
  13.  
  14.   MediaView1.Stop ' stops play and MediaView.Position is reset to 0
  15.  
  16.  

MediaView.Position is read/write , it returns the position or sets the position. (but you shouldn't need it for pause/play)

MediaView is a ready made player using MediaPlayer.
I would not say MediaPlayer is more robust but i would say it's easier to use MediaView unless you want more control than MediaView gives then go for MediaPlayer.
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
rj71 is in the usergroup ‘Regular’

BruceSteers said

Mediaview.Pause does pause it and resume where it left of when using MediaView.Play.

Only if you use MediaView.Stop will it not resume and start from the beginning
(Or maybe if you set MediaView.URL again in the play method)

The following code works exactly as expected for me.

(Post your code so we can see the problem)

Code (gambas)

  1.  
  2. Public Sub btnPlay_Click()
  3.  
  4.   MediaView1.Play  ' Plays or resumes at MediaView.Position
  5.  
  6.  
  7. Public Sub btnPause_Click()
  8.  
  9.   MediaView1.Pause ' stops play and MediaView.Position pauses where it is.
  10.  
  11.  
  12. Public Sub btnStop_Click()
  13.  
  14.   MediaView1.Stop ' stops play and MediaView.Position is reset to 0
  15.  
  16.  

MediaView.Position is read/write , it returns the position or sets the position. (but you shouldn't need it for pause/play)

MediaView is a ready made player using MediaPlayer.
I would not say MediaPlayer is more robust but i would say it's easier to use MediaView unless you want more control than MediaView gives then go for MediaPlayer.

Thanks Bruce. I've shut everything down for the day. I will double check my code tomorrow and report back.
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
rj71 is in the usergroup ‘Regular’
Hey Bruce, I was able to quickly check the code. I screwed up…I tried to re-use the Play button for resume. The play button does have a path to the movie and now I see clicking again as a resume just grabbed the movie again. Silly mistake. I do wonder though since I'm building this app to watch my movie collection, what if I do pause it, save the position (to db or file or something), close the app then come back the like the next day and play that movie from where i left off using the position that I saved? What am I not seeing in the Gambas wiki to help me solve this?

Code (gambas)

  1. Public Sub Button_Resume_Click()
  2.  
  3.   MediaView1.Postion = ValueBox1.Value 'how to do I start the movie from that point?? seems like I need to use seek but I'm not sure how.
  4.   MediaView1.Play
  5.  
  6.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
 MediaView1.Position is correct.

you have seen the wiki correct.

Maybe you have some other code making it go wrong.

post the project so we can see where the error is.
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’
Something simple like this should work.

Code (gambas)

  1.  
  2. Public Sub Form_Close()
  3.  
  4.   ' save URL and position
  5.   Settings["PlayFile"] = MediaView1.URL
  6.   Settings["PlayPosition"] = MediaView1.Position
  7.  
  8.  
  9. Public Sub ResumePlay()
  10.  
  11.   ' Resume play from last file/position
  12.   Dim sFile As String = Settings["PlayFile", ""]
  13.   If Not sFile Or If Not Exist(sFile) Then Return  
  14.  
  15.   MediaView1.URL = sFile
  16.   MediaView1.Position = Settings["PlayPosition", 0]
  17.   MediaView1.Play
  18.  
  19.  
  20.  
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’
Okay i think I found the issue.

Seems we have to wait for the media to be initialized and start playing before you can set position.

(I had a similar problem many moons ago trying to read the .Duration property that did not fill until playback had actually started playing)

Code (gambas)

  1.  
  2. Public Sub ResumePlay()
  3.  
  4.   ' Resume play from last file/position
  5.   Dim sFile As String = Settings["PlayFile", ""]
  6.   If Not sFile Or If Not Exist(sFile) Then Return  
  7.  
  8.   MediaView1.URL = sFile
  9.  
  10.   MediaView1.Play ' start playback
  11.  
  12.   While MediaView1.State <> Media.Playing  ' wait for play to begin
  13.     Wait 0.1
  14.   Wend
  15.  
  16.   Wait 0.5 ' wait another 1/2 second
  17.  
  18.   MediaView1.Position = Settings["PlayPosition", 0]  ' now it works :)
  19.  
  20.  
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’
I have a fix for the .Position bug
 MediaView, Setting Position before playback now works as expected (!387) · Merge requests · Gambas / gambas · GitLab

If Benoit thinks the fix is correct he will apply it, if not he will likely fix it correctly.  (although i think he's going to be away from home for a little while)

Either way we'll find the cure :)

I have attached a fixed MediaView component,

To use it..
Extract the archived MediaView folder to your projects ".src/" folder.
Then goto project properties/components and un-select gb.form.media to stop using the gambas built in version.

then this code will work as we both expect it to :)

Code (gambas)

  1.   MediaView1.URL = sFile
  2.   MediaView1.Position = Settings["PlayPosition", 0]
  3.   MediaView1.Play
  4.  

EDIT:
I just updated the archive.
I realized the $fStartUp variable was not reset to zero when it may or may not be set again.

So where it may or may not be set i have just set it to zero before hand in the SetPosition() procedure.

Code (gambas)

  1. Public Sub SetPosition(fPos As Float)
  2.  
  3.   Dim fLength As Float
  4.  
  5.   $fStartupPos = 0 ' Added this line
  6.  
  7.   Try fLength = $hPlayer.Duration
  8.  
  9.   If fLength Then
  10.     SetPos(fPos / fLength)
  11.   Else
  12.     $fStartupPos = fPos
  13.  
  14.  
  15.  

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#9
Regular
rj71 is in the usergroup ‘Regular’
Thanks Bruce! So I guess my thinking was right I just didn't know I needed a short wait before applying the Position . I just took that and adjusted my code to this and it works as expected by jumping to whatever number is in the valuebox:

Code (gambas)

  1. Public Sub Button4_Click()
  2. MediaView1.URL = "http://192.168.1.72/gbmovies/Battle- Los Angeles.mkv"
  3.   MediaView1.Play
  4.   Wait 0.5
  5.   MediaView1.Position = ValueBox1.Value
  6.  
  7.  

This app is turning out to be pretty cool looking and fun to build.
Online now: No Back to the top

Post

Posted
Rating:
#10
Guru
BruceSteers is in the usergroup ‘Guru’
it seems very dependent on the fact .Duration has not yet been set.

Trying to change .Position before the file has started playing and filled the .Duration property is where the .Position bug happens.

Just using Wait 0.5 may be a bit hit or miss.

So something like this i think should handle it better…

Code (gambas)

  1. Public Sub Button4_Click()
  2.  
  3.   MediaView1.URL = "http://192.168.1.72/gbmovies/Battle- Los Angeles.mkv"
  4.   MediaView1.Play
  5.  
  6.   While Not MediaView1.Duration
  7.     Wait 0.1
  8.   Wend
  9.  
  10.   MediaView1.Position = ValueBox1.Value
  11.  
  12.  
  13.  
Online now: No Back to the top

Post

Posted
Rating:
#11
Regular
rj71 is in the usergroup ‘Regular’

BruceSteers said

it seems very dependent on the fact .Duration has not yet been set.

Setting .Position before the file has started playing and set .Duration is where the .Position bug happens.
Just using Wait 0.5 may be hit or miss.

So something like this should handle it better…

Code (gambas)

  1. Public Sub Button4_Click()
  2.  
  3.   MediaView1.URL = "http://192.168.1.72/gbmovies/Battle- Los Angeles.mkv"
  4.   MediaView1.Play
  5.  
  6.   While Not MediaView1.Duration
  7.     Wait 0.1
  8.   Wend
  9.  
  10.   MediaView1.Position = ValueBox1.Value
  11.  
  12.  
  13.  

Ok. I will adjust my code with the While Not you added. Thanks Bruce!
Online now: No Back to the top
1 guest and 0 members have just viewed this.