I want to create a simple video player with C++ and wxWidgets. I put wxMediaCtrl and wxFileDialog controls and created this code for button click event:
wxFileDialog * fopen = new wxFileDialog(this, wxT("Wybierz plik"), wxT(""), wxT(""), wxT("MP4 file (*.mp4)|*.mp4|AVI file (*.avi)|*.avi"));
if (fopen->ShowModal() == wxID_OK)
{
wxString fname = fopen->GetFilename();
media->Load(fname); // media is pointer to wxMediaCtrl object
media->Play();
}
delete fopen;
When I open file, it doesn't play. I have no idea what to do.
The documentation states:
For general operation, all you need to do is call Load() to load the file you want to render, catch the EVT_MEDIA_LOADED event, and then call Play() to show the video/audio of the media in that event.
So the problem looks to be that the file hasn't finished loading when you try to play it. You can also see the mediaplayer sample in the samples directory of your wxWidgets installation for more details.
Related
I am using wxWidgets samples code for media player. Here first we need to select the file from the wxFileDialog and on clicking play button it will play the video.
But I don't want to select the file from the wxFileDialog, I am passing the video path in DoOpenFile(path, bNewPage); and then clicking on play button then the video is not playing.
void wxMediaPlayerFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
{
DoOpenFile(_("D:\\myvideo.mp4"), false);
wxMediaPlayerNotebookPage* currentpage = (wxMediaPlayerNotebookPage*)m_notebook->GetCurrentPage();
....
....
....
}
I have the following problem. I am using the Borland 2006 Compiler and I am trying to include an animation in my applicaton. First I added the TAnimate Object and then in the ObjectInspector under "FileName", every time I try to add an .avi, the Compiler says "AVI cannot be opened". Am I doing something wrong or isn't it that simple to just put a .gif or .avi into that Objectproperty?
Edit // Here ist Some CodeExample, everytime i press the button, it throws an exception and tells me that the avi File cannot be opened
void __fastcall THauptmenue_Login::Button1Click(TObject *Sender)
{
Animate1->FileName = ("C:\\Users\\Kevin\\Desktop\\C++ Gifs");
}
The FileName you showed doesn't look complete. It looks more like a path to a folder instead of a file.
In the Object Inspector, beside the FileName text box is a [...] button which brings up a file browser dialog which can add a full path and name to a file.
addendum:
If you are using the Object Inspector to pick a filename from the disk you do not need to specify a FileName property value in the code.
This overwrites any previous FileName property value.
Animate1->FileName = "C:\\Users\\Kevin\\Desktop\\C++ Gifs";
I'm using visual c++ and i am totally new on it.
I have a form with a button, how when i click on it the file will open in new form?.
I tried to find a solution around but in vain.
First you need to add Adobe Reader COM component to your Toolbox.
Than drag it (like a simple button )into your "Form2" and name it AdRead for example.
In your first Form insert this code to your button so you can open "Form2"
Form2 ^ anyname = gcnew Form2();
anyname->Show();
this->Hide();
And put this code into AdRead
String^ Path ="here put the path of your specific file";
AdRead->src=Path;
Your path should be like "c:\\folder\\folder\\File.pdf"
I try to play mp3 files declared in the resource, but it show:
Btn clicked
current media: "qrc://sound/sound/FarAway.mp3"
Error : QMediaPlayer::FormatError
Media state : QMediaPlayer::InvalidMedia
Here's how I set media:
player = new QMediaPlayer(this);
player->setMedia(QUrl(mediaFilePath));
qDebug() << "current media: " << player->currentMedia().canonicalUrl().toString();
connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(handleStateChanged(QMediaPlayer::State)));
connect(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), SLOT(handleMediaStateChanged(QMediaPlayer::MediaStatus)));
connect(player, SIGNAL(error(QMediaPlayer::Error)), SLOT(handleError(QMediaPlayer::Error)));
According to this post it said QMediaPlayer need to be called play() after the callback of mediaStatusChanged(), which is what I've done exactly. So what's the problem???
P.S. I could play the mp3 file from the QMediaPlayer Example as local file.
UPDATE 1: I can play the mp3 file as local file...
Your problem is now no longer a problem, you can play a Qt resource in the QMediaPlayer. Answer found here, and I'm confirming it here in case people are looking.
This code works for me when testing in my local project.
player->setMedia(QUrl("qrc:/audio/audio/Revival_Song01.mp3"));
You should play a file from disk; not a Qt resource. Since the resources are not supported yet. You can copy the file from resource to your hard drive on the fly and then play it :
QFile::copy(":/files/FarAway.mp3" , "/some/path/FarAway.mp3");
Is there any way to load qt compiled c++ code in maya?
//example code
void MainWindow::on_pushButton_clicked()
{
ui->labell->setText("Hello");
}
actually i was created basic ui with text and push button, what i want is text should change to hello when i push button and i achieved that. so this connections were made with above code, after compiling this all works fine but when i load ui file in maya and i pushes the button text doesn't changes because actually code was written in c++. so, is there any alternative to load that code too along with ui file?
thank you,
Anvesh Chary
To load a .ui file in Maya, I've previously done this in python, I'm not sure about C++ but I don't believe maya interprets C++ directly anyway (I could be wrong there).
import maya.cmds as cmds
ve = cmds.about(version=True)
conv = "%s"%ve
versionOutput = float(conv[0:4])
def mayaVers():
cmds.warning("You're using Maya %s! You need to be using Maya 2011 or greater to be compatible with this script.\n" % conv);
def loadUIWindow():
if versionOutput >= 2011:
if (cmds.dockControl('dockUIWindow', exists=True)):
cmds.deleteUI('dockUIWindow')
scriptsDirectory = cmds.internalVar(usd=True)
UIWindow = cmds.loadUI(uiFile=scriptsDirectory + "/uifilename.ui")
dockSoftMod = cmds.dockControl('dockUIWindow',area="left", content='uiwindowname', label="")
else:
mayaVers()
loadUIWindow()
Here's how I've done it in the past, if you're just looking to source a UI file into the Maya session, this is how it can be done.
Obviously you'll need to either put your ui file in the scripts directory, or change the uiFilePath to your file.
Also, the content flag in the dockControl is important, this needs to be the name of the window or control that you're trying to dock. Let's say you have called your UI file wrapper 'win', the content flag would need to be the same.
EDIT
After you load the UI file, you can edit any element in the window if you know it's name.
cmds.button('ParentBtn', edit=1, command="parentObject()")
Hope this helps.