Why closing one movieplayer disables other instances?

Hello. I would like to understand how is it possible to play a movie from url, stopping it and play another movie. I have a window with two Movieplayer. With this code the first movie starts and is played:

var m as movieplayer
m=movieplayer1
window2.show
m.Movie = Movie.OpenURL(webaddress+“movie1.mp4”)
m.Play

but since it seems running asynchronous and I want to stop it beforehand, I use the follwing code:

while true
if m.position>15 then
m.close
exit
end if
wend

Only “close” effectively stops it, while “stop” does’nt.

But if now I want to play something again, if I try to do this using the same movieplayer I get a “Nil Object Exception”. I suppose this happens because when you close an object it is removed from memory.
Ok, but then I added a second movieplayer, which should be independent from the first one, but if I try to play a movie with Movieplayer2 after having closed the first one, I incur in the same error. What is wrong? Thank you.

What xojo version?
What os version?
Can you upload a simple binary project of it happening?

It is Xojo 2021 r3.1 (latest) on Windows 10

As I see, it is not possible to upload a project but image files only.

Anyway, to reproduce the problem just create a simple project with one window and two Movieplayer, and execute this code:

window2.show
window2.movieplayer1.Movie = Movie.OpenURL([any URL to a movie file])
window2.movieplayer1.Play

while true
if window2.movieplayer1.position>15 then 'I want to stop it after 15 seconds
window2.movieplayer1.close
exit
end if
wend

window2.movieplayer2.Movie = Movie.OpenURL([any URL to a movie file])
'here the program stops and NilObjectException occurs, next code is not executed

window2.movieplayer2.play
window2.show

This is why I’d really like to see your demo project as that code doesn’t do what you’re explaining, in fact it doesn’t even show the movie on the first player as you’re sitting in a while loop not allowing the UI/player to update and play. If I move the code into a timer instead of a loop that maxes out your cpu core then it works as expected so you must me Closing player 2 some other way which is why I asked for a demo so we can see where it’s going wrong and suggesting fixes instead of guessing :slight_smile:

There’s plenty of free file uploading services around, dropbox, onedrive, mediafire.

OK thanks. Here is a link to the project in Sync cloud

MoviePlayer2 is a child of MoviePlayer1 so when you close 1, it also closes 2.

Right click MP2 and select Unparent near the bottom.

But please, use a timer instead of a loop.

1 Like

Tank you again. This was really helpful. I still don’t understand how can you realize that a second control is a child of the first one. It is not shown in the Inspector and apparently nowhere…

If you click the control you will see its parent is highlighted with a red border.