Page 1 of 1
Program freezes when calling stop in MediaPlayerEndReached
Posted: 09 Mar 2011 09:32
by mario123
I have a C# program with a VLC activeX on a form. If a call the playlist.stop function in de MediaPlayerEndReached event handler, my program freezes.
I am using VLC activeX v1.1.7
Code: Select all
private void axVLCPlugin21_MediaPlayerEndReached(object sender, EventArgs e)
{
this.axVLCPlugin21.playlist.stop();
}
I also tried the same thing using Builder. So, a Builder form with a VLC activeX on it. I also called the playlist.stop in the MediaPlayerEndReached. Again my program freezes.
Code: Select all
void __fastcall TfrmEventViewer::VLCPlugin21MediaPlayerEndReached(TObject *Sender)
{
VLCPlugin21->playlist->stop();
VLCPlugin21->playlist->clear();
}
Does anybody have an idea why this is happening?
Re: Program freezes when calling stop in MediaPlayerEndReach
Posted: 10 Mar 2011 15:00
by Dandy
Infinite recursion?
Maybe playlist.stop() triggers MediaPlayerEndReached event?
If the video reaches the end, doesn't it stop automatically?
Re: Program freezes when calling stop in MediaPlayerEndReach
Posted: 11 Mar 2011 08:20
by mario123
Yes, if the video reaches the end, it stops automatically. But you can still see the last image of the video and I would like to remove that. So I would like to call the stop function to clean up.
I don 't think it's infinite recursion because I have a breakpoint in my debugger at the beginning of the MediaPlayerEndReached event. It doesn't hit that breakpoint a second time.
I also tried posting a windows message to myself and calling the stop function in the event handler. So now I have something like this:
Code: Select all
void __fastcall TfrmEventViewer::VLCPlugin21MediaPlayerEndReached(TObject *Sender)
{
//VLCPlugin21->playlist->stop();
PostMessage(this->Handle,WM_PLAYLIST_STOP,0,0);
}
void __fastcall TfrmEventViewer::WMPlaylistStop(TMessage& message)
{
VLCPlugin21->playlist->stop();
}
But this doesn't solve anything. My program reaches the WMPlaylistStop() function but again my program freezes when I call the stop function.
I also looked up the vlc stop function. It looks like this:
Code: Select all
void libvlc_media_player_stop( libvlc_media_player_t *p_mi )
{
libvlc_state_t state = libvlc_media_player_get_state( p_mi );
lock_input(p_mi);
release_input_thread( p_mi, true ); /* This will stop the input thread */
/* Force to go to stopped state, in case we were in Ended, or Error
* state. */
if( state != libvlc_Stopped )
{
set_state( p_mi, libvlc_Stopped, false );
/* Construct and send the event */
libvlc_event_t event;
event.type = libvlc_MediaPlayerStopped;
libvlc_event_send( p_mi->p_event_manager, &event );
}
if( p_mi->input.p_resource != NULL )
input_resource_TerminateVout( p_mi->input.p_resource );
unlock_input(p_mi);
}
Probably the lock_input() or the release_input_thread() function causes the problem.
Re: Program freezes when calling stop in MediaPlayerEndReach
Posted: 14 Mar 2011 07:04
by jack.ting
Hey,
I've the same trouble experience on javascript programming.
Here's what I found and my suggestion:
1. there's no need to call "playlist->stop()" at all, it will stop automaticlly (no matter it's the last item of the playlist or not).
2. It seems that the "MediaPlayerEndReached" is designed for trigger of playing next item in the playlist (for looping control or for randomize control or ...).
3. If you want to do something else like "playlist->clear()", you have to wait until the "stoped" state is reached.
so, in javascript:
1. I register the "MediaPlayerEndReached" event to a check the state is "ended" or not, if yes play next item (for looping), otherwise do nothing.
2. and call setTimeout() or setInterval() to wait several ms then checking the state of VLC instance, to make sure the "stoped" state is reached before I processing the next command.
Re: Program freezes when calling stop in MediaPlayerEndReach
Posted: 14 Mar 2011 14:27
by mario123
Hi,
Thanks for you suggestion. I am not using javascript, so I don't have setTimeout() or setInverval(). But I can create a timer, using a callback function. So I tried that. In my callback function I first verify the state and if it is in the ENDED state, I call the playlist->stop() function. I know, the stop function is not needed here, but I just wanted to test that it did not freeze my program. And indeed, it works!
Now I got curious, what would happen if I do the same thing in the "MediaPlayerEndReached"? So now, I only call playlist->stop() in the ENDED state. Now, my program freezes again.
So, the solution with the timer works, but it probably has nothing to do with the ENDED state.
I know, I don't really need the playlist->stop(), but I do would like to know in which cases it can be used and when not.
Re: Program freezes when calling stop in MediaPlayerEndReach
Posted: 16 Mar 2011 06:32
by jack.ting
Sorry, that's my question, too.
I'm trying to digging more information the source code.
But currently, I'm focus on something else, I just could spend few time on it.