Page 1 of 2
CursorTask - VideoPlayer
Posted: 09 Jun 2025, 11:15
by elenamon
Dear all,
I am currently working on the development of a custom pipeline using BCI2000. My goal is to provide video feedback to the user. At this stage, the video should be played as-is, although in the future I plan to implement dynamic control of playback speed. For this purpose, I have referred to a previous forum thread (
viewtopic.php?t=3794). So I'm using the MyModifiedVideoPlayer class previously discussed.
Specifically, I am using the CursorTask module as a template, and I am attempting to play a video at standard speed during the feedback phase. However, I am encountering an issue: the video does not play, and no error messages are displayed.
Below, I have provided the relevant code related to video playback:
Code: Select all
MyCursorTask::MyCursorTask()
{
[...]
mpVideoPlayer = new MyModifiedVideoPlayer(mrWindow, 1.0); // declared also in the header
mSpeed = 1.0;
mpVideoPlayer->SetSpeedup(mSpeed);
}
void MyCursorTask::OnInitialize(const SignalProperties& /*Input*/)
{
[...]
mrWindow.Show();
source_video = ".prog/video/myvideo.mp4";
mpVideoPlayer->SetFile(source_video);
AppLog.Screen << mpVideoPlayer->SetFile(source_video) << std::endl;
mSpeed = 1.0;
mpVideoPlayer->SetSpeedup(mSpeed);
}
void MyCursorTask::OnFeedbackEnd()
{
[...]
mpVideoPlayer->Hide();
}
void MyCursorTask::DoFeedback(const GenericSignal& ControlSignal, bool& doProgress)
{
[...]
mpVideoPlayer->Show();
mSpeed = 1.0;
mpVideoPlayer->SetSpeedup(mSpeed);
mpVideoPlayer->Play();
}
Based on my observations, the application log (
Code: Select all
AppLog.Screen << mpVideoPlayer->SetFile(source_video) << std::endl;
) suggests that the video is not being loaded properly, as the corresponding log entry returns zero. Additionally, I would like to note that, unlike the original CursorTask, I have disabled the entire FeedbackScene that involves the cursor and target display.
Any assistance or suggestions you could provide would be greatly appreciated.
Thank you in advance for your support.
Re: CursorTask - VideoPlayer
Posted: 09 Jun 2025, 12:05
by mellinger
Hi,
I can offer two pieces of advice. First, the VideoPlayer::SetFile() method does not return an error string. Rather, it returns a reference to the VideoPlayer instance itself. To test for success, when loading a file, use VideoPlayer::IsOpen() and VideoPlayer::Error(). The latter gives you an error string if an error occurred.
Second, the file name you are using seems to have a typo in it. Between the initial dot, and the "prog" directory name, there should be a slash "/".
HTH
Re: CursorTask - VideoPlayer
Posted: 10 Jun 2025, 11:18
by elenamon
Hi,
thank you very much for your suggestions. I have changed the path of the video as you suggested and tested using the methods you mentioned. According to the results the video is now correctly loaded but actually it still does not appear on the mrWindow (black screen). No errors occur when the application is compiled not even the applog reports anomalies. Do you have any other suggestion? Which other video player's attribute or method should I check?
Thanks in advance
Re: CursorTask - VideoPlayer
Posted: 10 Jun 2025, 11:37
by mellinger
With some video files, there might be playback issues. To check whether BCI2000 is able to play back your video, you may use the BCI2000MediaPlayer tool (bci2000/tools/BCI2000MediaPlayer/BCI2000MediaPlayer.exe). To run it with a certain media file, start it from the command line and enter the media file name after "BCI2000MediaPlayer.exe":
Code: Select all
BCI2000MediaPlayer ../../prog/video/myvideo.mp4
Re: CursorTask - VideoPlayer
Posted: 11 Jun 2025, 04:48
by elenamon
Hi,
thank you again. I've just performed the test with the BCI200MediaPlayer as suggested and I've verified that the video is correctly open and playback.
So I really cannot figure it out what's wrong with my BCI2000 application module.
Is it possible to initialize and see a second window within the CursorTask application only to see the video? Could it be a useful test to try?
It is only a proposal, so you if you have any other different suggestions I would really appreciate to try them.
Thank you again in advance for the help
Re: CursorTask - VideoPlayer
Posted: 11 Jun 2025, 06:51
by mellinger
From your code, it seems that you are playing back during the feedback phase, but you may have removed the code that enters the feedback phase.
Apart from that, the DoFeedback() function is called repeatedly during feedback, and calling Show() and Play() repeatedly is probably not what you want.
My suggestion is to create an OnStartRun() function if it doesn't exist, and move the content of DoFeedback() there.
Re: CursorTask - VideoPlayer
Posted: 11 Jun 2025, 06:53
by elenamon
Sorry for the second reply, I want to add that in the DoFeedback section I've tested if the video is open and if it is playing, and it reported that is open and is playing during the feedback, but actually I'm not able to see it.
Code: Select all
if (mpVideoPlayer->IsPlaying()) {
AppLog.Screen << "playing" << std::endl;
}
if (mpVideoPlayer->IsOpen()) {
AppLog.Screen << "Open" << std::endl;
}
So the problem seems to be related to where the video is open and played, why I'm not able to see it.
Hope that this can help in the final resolution of my problem
Thanks again
PS. I've just seen your last answer. Thank you, I'll try your last suggestion and I'll reply back. Thanks
Re: CursorTask - VideoPlayer
Posted: 11 Jun 2025, 08:56
by mellinger
BTW, I just noticed that you didn't set a rectangle for your video. You probably want to see it in native resolution, so use
Code: Select all
GUI::Rect rect = { 0.5, 0.5, 0.5, 0.5 };
mpVideoPlayer->SetObjectRect(rect);
mpVideoPlayer->SetScalingMode(GUI::GraphObject::AdjustBoth);
in the constructor.
Re: CursorTask - VideoPlayer
Posted: 11 Jun 2025, 10:24
by elenamon
Thank you again for the new suggestions.
Trying to move the contenet of DoFeedback() to OnStartRun() nothing changed: in the Applog is reported that the video is open and played but it is not visible in the mrWindow.
I've add the definition of the rect as suggested and in the system Log appear the following errors before starting the session:
Code: Select all
resource deadlock would occur: resource deadlock would occur.
2025-06-11T16:16:15.429 - Application error, MyCursorTask::Initialize: Unhandled exception of type std::system_error:
resource deadlock would occur: resource deadlock would occur
Terminating MyCursor module.
2025-06-11T16:16:16.439 - Application error:
Lost connection to Application.
Any other suggestions?
Thanks a million for the support
Re: CursorTask - VideoPlayer
Posted: 11 Jun 2025, 10:39
by mellinger
I'd suggest to remove
from OnInitialize().
Re: CursorTask - VideoPlayer
Posted: 11 Jun 2025, 11:26
by elenamon
Unfortunately removing the suggested line nothing changes and the error on the System Log is still the same.
As the problem seems to be in OnInitialize(), I transcript here all the code about that section (not only the lines ralted to the VideoPlayer), hoping tha this can help in finding the solution.
Code: Select all
void MyCursorTask::OnInitialize(const SignalProperties& /*Input*/)
{
float feedbackDuration = Parameter("FeedbackDuration").InSampleBlocks();
mMaxFeedbackDuration = static_cast<int>(Parameter("MaxFeedbackDuration").InSampleBlocks());
mrWindow.Show();
source_video = "./video/myvideo.mp4";
mpVideoPlayer->SetFile(source_video);
AppLog.Screen << "video loaded - " << source_video << std::endl;
AppLog.Screen << mpVideoPlayer->Error() << std::endl;
if (mpVideoPlayer->IsOpen()) {
AppLog.Screen << "open" << std::endl;
}
mpVideoPlayer->Hide();
mSpeed = 1;
mpVideoPlayer->SetSpeedup(mSpeed);
}
Thanks for the help
Re: CursorTask - VideoPlayer
Posted: 11 Jun 2025, 11:36
by mellinger
There is nothing suspicious in your OnInitialize() function.
How do you obtain the mrWindow reference in the constructor of your task?
Re: CursorTask - VideoPlayer
Posted: 11 Jun 2025, 11:59
by mellinger
I reproduced the issue on my machine, so I will be able to help you more efficiently. I will come back to you once I identified the source of the issue.
Re: CursorTask - VideoPlayer
Posted: 11 Jun 2025, 12:08
by elenamon
The mrWindow is defined in the header file in this way:
and in the .cpp file is initialized as
Thanks a million to have riproduced my issue. I'll wait for yuor precious reply.
Re: CursorTask - VideoPlayer
Posted: 11 Jun 2025, 16:57
by mellinger
There were two independent issues, one that caused the error message, and one that caused the black screen.
I fixed both of them, and the example code now works on my machine.
Please do an SVN update on your side and let me know if the issues persist for you.