Splash screen with video Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
xargon
Knows some wx things
Knows some wx things
Posts: 25
Joined: Wed Feb 25, 2009 3:00 pm

Splash screen with video

Post by xargon » Thu Jan 14, 2016 2:48 pm

I created a small class using wxMediaCtrl that will play a video as a splash screen. The code for the class is as follows:

HEADER:

Code: Select all

#include <wx/wx.h>
#include <wx/mediactrl.h>

#include "macros.h"

class SplashVideo: public wxFrame
{
public:
    SplashVideo(const wxString & video_path,
                wxWindow * parent, wxWindowID id,
                const wxPoint & pos=wxDefaultPosition,
                const wxSize & size=wxDefaultSize,
                long style=wxBORDER_SIMPLE|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP);

    void OnMediaFinished(wxMediaEvent& event);
    void OnMediaLoaded(wxMediaEvent& event);

private:
    const int ID_MEDIA_CTRL = wxNewId();    
    wxMediaCtrl *               media_ctrl;
};
The implementation is also quite simple and is:

Code: Select all

SplashVideo::SplashVideo(const wxString & video_path,
                         wxWindow * parent, wxWindowID id, const wxPoint & pos,
                         const wxSize & size, long style)
    :wxFrame(parent, id, wxEmptyString, pos, size,
             style | wxFRAME_TOOL_WINDOW | wxFRAME_NO_TASKBAR)
{
    SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
    media_ctrl = new wxMediaCtrl(this, ID_MEDIA_CTRL, video_path);
    this->CenterOnScreen();
    
    this->Connect(ID_MEDIA_CTRL, wxEVT_MEDIA_LOADED,
                  wxMediaEventHandler(SplashVideo::OnMediaLoaded));

    this->Connect(ID_MEDIA_CTRL, wxEVT_MEDIA_FINISHED,
                  wxMediaEventHandler(SplashVideo::OnMediaFinished));
}

void SplashVideo::OnMediaLoaded(wxMediaEvent & event)
{
    this->Show(true);
    media_ctrl->Play();
}

void SplashVideo::OnMediaFinished(wxMediaEvent& event)
{
    this->Close(true);
}
Now I can call this from my application as:

Code: Select all

class MyApp : public wxApp
{
public:
    bool OnInit()
    {
        wxFrame * app_win = NULL, wxID_ANY, wxT("App"));
        {
            new SplashVideo(wxT("/home/xargon/media.avi"),
                            app_win, wxID_ANY);
        }

        app_win->Show(true);
        return true;
    }
};

wxIMPLEMENT_APP(MyApp);
This actually works quite well. My only issue is that the frame gets constructed and shown along with the splash screen video player and I would like the frame to be shown after the splash screen is done playing. Perhaps this could be done with the wxWidget events but I have not been able to figure out a good way to do so. Any help would be appreciated.

DenDev
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 223
Joined: Mon Jan 19, 2015 1:45 pm

Re: Splash screen with video

Post by DenDev » Thu Jan 14, 2016 3:27 pm

I think some of your code is broke (construction of app_win), but you should consider to create app_win as not visible (remove "app_win->Show(true)" from app::OnInit) and then display it after you close / destroy the splash screen (in OnMediaFinished). Also, your splash screen should probably be created without any parent since having an invisible parent is problematic.
I have a bad habbit of not testing the code I post :D

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Splash screen with video

Post by doublemax » Thu Jan 14, 2016 3:40 pm

Another option could be to implement the splash screen as a modal dialog. Then the main frame would only get created after the dialog is closed.
Use the source, Luke!

xargon
Knows some wx things
Knows some wx things
Posts: 25
Joined: Wed Feb 25, 2009 3:00 pm

Re: Splash screen with video

Post by xargon » Thu Jan 14, 2016 4:01 pm

Thanks for the comments guys. Yes, could be that some of the code is not optimal. Just starting with wxWidgets.

Regarding the parent for the Splash screen, this is because it was like this in the sample, so I am assuming it is not a problem to do so.

xargon
Knows some wx things
Knows some wx things
Posts: 25
Joined: Wed Feb 25, 2009 3:00 pm

Re: Splash screen with video

Post by xargon » Thu Jan 14, 2016 4:10 pm

doublemax wrote:Another option could be to implement the splash screen as a modal dialog. Then the main frame would only get created after the dialog is closed.
Is it possible to have the wxDialog inherited class with no taskbar as I have with my wxFrame derived SplashVideo class?

[EDIT]: Never mind as I could just change wxFrame to wxDialog and it works (calling ShowModal() at the right time)...
Last edited by xargon on Thu Jan 14, 2016 4:26 pm, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 15263
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Splash screen with video

Post by doublemax » Thu Jan 14, 2016 4:26 pm

Is it possible to have the wxDialog inherited class with no taskbar as I have with my wxFrame derived SplashVideo class?
Although it's only documented for wxFrame, setting the wxFRAME_NO_TASKBAR style flag for wxDialog should work, too.
Use the source, Luke!

xargon
Knows some wx things
Knows some wx things
Posts: 25
Joined: Wed Feb 25, 2009 3:00 pm

Re: Splash screen with video

Post by xargon » Thu Jan 14, 2016 4:27 pm

Our posts just crossed :-)

Post Reply