How do I trap an invalid object error

Post

Posted
Rating:
#1 (In Topic #1424)
Regular
rj71 is in the usergroup ‘Regular’
This app is Gambas 3.18, I'm trying to "recreate" the MediaView1.State which is not until 3.19 by using a couple of timers and 2 valueboxes. The timer in the code below compares the 2 valueboxes and if they are equal then mediaview1 must be paused. Otherwise mediaview is playing. Believe it or not it actually works fairly well, the problem I'm having is when I exit the app or close the form I get an invalid object error. I've tried stopping the timers, stopping mediaview and I still get the error. I think I must have my error handling wrong? Can some advise on how to better handle the error?

Code (gambas)

  1. Public Sub Timer5_Timer()
  2.  
  3.    Try mediavstatus.Value = movpos.Value
  4.      'something went wrong
  5.    Else
  6.   Wait 1.0
  7.  
  8.  
  9.    If mediavstatus.Value = movpos.Value Then  '<<<<<<<<<------- this is where the error gets thrown
  10.     'must be paused
  11.     mediavstatustext.Text = "paused"
  12.    
  13.     Else
  14.       'must be playing
  15.       mediavstatustext.Text = "playing"
  16.  Endif 'end try
  17.  
  18. Wait 0.5
  19.  
  20.  
  21.  
  22.  
  23.  
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
 It's the use of Wait.

When you call Wait the event loop runs and closes the window making the objects invalid in the next bit of code.

try not using Wait
Online now: No Back to the top

Post

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

BruceSteers said

It's the use of Wait.

When you call Wait the event loop runs and closes the window making the objects invalid in the next bit of code.

try not using Wait

Ah. Damn. Wait is how I am getting if the value boxes are different essentially telling me if mediaview is paused or playing. Thanks Bruce. Looks like I need to come up with something different.
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
maybe something like this…

Code (gambas)

  1.  
  2. Public Sub Timer5_Timer()
  3.  
  4.   Dim fPos as Float
  5.   fPos = MediaView1.Position
  6.  
  7.   Wait 0.1
  8.   If Not Object.IsValid(MediaView1) Then Return ' window is closing
  9.  
  10.    If MediaView1.Position = fPos Then
  11.     'must be paused
  12.     mediavstatustext.Text = "paused"
  13.      
  14.     Else
  15.       'must be playing
  16.       mediavstatustext.Text = "playing"
  17.    
  18. ' catch any errors anyway
  19.   Debug Error.Text
  20.  
  21. Public Sub Form_Close()
  22.  
  23.   Timer5.Stop
  24.  
  25.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
Or just remove gb.media.form component from the project properties and add the later version to your projects .src folder

from here comp/src/gb.media.form/.src · master · Gambas / gambas · GitLab

download these 3 files
FMediaPlayer.form
FMediaPlayer.class
MediaView.class

then you will have…
  1. the latest MediaView regardless of the gambas version.
  2. the MediaView source code in your own project you can tweak to your hearts content :)
Online now: No Back to the top

Post

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

BruceSteers said

Or just remove gb.media.form component from the project properties and add the later version source to your projects .src folder

from here comp/src/gb.media.form/.src · master · Gambas / gambas · GitLab

download these 3 files
FmediaPlayer.form
FMediaPlayer.class
MediaView.class

then you will have…
  1. the latest MediaView regardless of the gambas version.
  2. the MediaView source code in your own project you can tweak to your hearts content :)

I think I'll try this. Thanks Bruce!
Online now: No Back to the top

Post

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

BruceSteers said

Or just remove gb.form.media from the project properties and add the later version to your projects .src folder

from here comp/src/gb.media.form/.src · master · Gambas / gambas · GitLab

download these 3 files
FmediaPlayer.form
FMediaPlayer.class
MediaView.class

then you will have…
  1. the latest MediaView regardless of the gambas version.
  2. the MediaView source code in your own project you can tweak to your hearts content :)

Hey Bruce, before I get ahead of myself….the mediaview1.state is what I'm looking for, right? That basically tells me if mediaview is playing, paused or stopped? Just want to make sure I'm headed in the right direction.
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’
 Yes, MediaView.State did not exist until i requested it a couple of years ago when i made the MPRIS stuff.

MediaView.State will show a value that corresponds to Media.Playing , Media.Paused , Media.Stopped etc.
Online now: No Back to the top

Post

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

BruceSteers said

Yes, MediaView.State did not exist until i requested it a couple of years ago when i made the MPRIS stuff.

MediaView.State will show a value that corresponds to Media.Playing , Media.Paused , Media.Stopped etc.

Thanks Bruce!
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
rj71 is in the usergroup ‘Regular’
 Hey Bruce, I tried your timer code in my current project but sometimes it works and sometimes it doesn't. This form has the given video start at form open, your code sometimes takes 10-15 seconds before it tells me the mediaview is playing. I'll try to figure out why. As for your other suggestion, I created a fresh app (3.18) and downloaded the files to experiment with that. I put those 3 files in the .src directory and gb.media.form is NOT in the project properties. Right from the start I get "unknow identifier: MediaPlayer" on line 9 of FMediaPlayer.class. Did I miss a step? Your instructions seem fairly clear.
Online now: No Back to the top

Post

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

rj71 said

Hey Bruce, I tried your timer code in my current project but sometimes it works and sometimes it doesn't. This form has the given video start at form open, your code sometimes takes 10-15 seconds before it tells me the mediaview is playing. I'll try to figure out why. As for your other suggestion, I created a fresh app (3.18) and downloaded the files to experiment with that. I put those 3 files in the .src directory and gb.media.form is NOT in the project properties. Right from the start I get "unknow identifier: MediaPlayer" on line 9 of FMediaPlayer.class. Did I miss a step? Your instructions seem fairly clear.

This is strange. I just did 10 consecutive tests with your timer code. It worked just fine. I do not know why I had trouble with it initially. That issue "appears" to be solved  :lol: I would like to still play around with getting the new Mediaview code in a 3.18 app though.
Online now: No Back to the top

Post

Posted
Rating:
#12
Guru
BruceSteers is in the usergroup ‘Guru’
MediaPlayer is from gb.media

you must still add gb.media for the MediaPlayer.class that MediaView uses.

just remove gb.media.form that is the now imported MediaView.class

then we can forget the Timer function ;)
Online now: No Back to the top

Post

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

BruceSteers said

MediaPlayer is from gb.media

you must still add gb.media for the MediaPlayer.class that MediaView uses.

just remove gb.media.form that is the now imported MediaView.class

then we can forget the Timer function ;)

Thanks Bruce. I should have realized that  :lol:
Online now: No Back to the top

Post

Posted
Rating:
#14
Regular
rj71 is in the usergroup ‘Regular’
 Sorry to bother you again Bruce. I feel really silly about this but I don't understand how to play a video with this mediaview control. The code looks way more complex than what I've done with playing videos. Normally I would have 'MediaView1.URL = "path/to/some/file" then MediaView1.Play. I assume there is more to it?
Online now: No Back to the top

Post

Posted
Rating:
#15
Guru
BruceSteers is in the usergroup ‘Guru’
 I don't know what you mean?

The code is what MediaView is.
You should not be using (modifying) the actual MediaView code to just play stuff.

by adding the component code to your project you are simply importing your own version of MediaView.

usage of a MediaView in your project is then the same as normal.
Online now: No Back to the top

Post

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

BruceSteers said

I don't know what you mean?

The code is what MediaView is.
You should not be using (modifying) the actual MediaView code to just play stuff.

by adding the component code to your project you are simply importing your own version of MediaView.

usage of a MediaView in your project is then the same as normal.

Thanks Bruce. I'll recheck to see what I did wrong. I'm actually working on another thing at the moment. I think I finally understand how to use a background task!
Online now: No Back to the top
1 guest and 0 members have just viewed this.