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();
....
....
....
}
Related
In a GUI I'm working on I intend to use VLC (axVLCplguin) to display camera feed. I want to test it with an offline video stored on my disc, however, each time I click on the button, which should start the video, I get a runtime error (caused on line VLC -> playlist -> add(path, NULL, NULL); ).
I assume, that the given MRL address - the first parameter of the method - is not in a correct format: file://C:/Users/User/Desktop/AMT.mp4
(viz.: https://wiki.videolan.org/Media_resource_locator/).
I've seen many tutorials, how to get a video feed in WinForms using the VLC plugin, but none of them had an included code in C++ (only in C#, where the simple absolute path to the video did the work).
void Grimr::MainForm::chbox_live_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
pbox_drawing->Visible = false;
if (chbox_area->Checked)
{
VLC->Visible = true;
VLC->AutoPlay = false;
String^ path = "C:\\Users\\User\\Desktop\\AMT.mp4";
VLC->playlist->add(path, NULL, NULL);
VLC->playlist->play();
}
}
I am creating a Qt application and I have an image that I want to use for a button instead of text. Unfortunately all that shows up is an empty button.
I've tried two different methods to get it to show up with the same results for both methods.
Code for Method 1:
ui->setupUi(this);
QPixmap pix(":/svg/resources/menu.svg");
int w = ui->menuButton->width();
int h = ui->menuButton->height();
ui->menuButton->setMask(pix.scaled(w,h,Qt::KeepAspectRatio).mask());
I found the info for the second method here: Adding image to QPushButton on Qt
Code for Method 2:
ui->setupUi(this);
QIcon icon(":/svg/resources/menu.svg");
ui->menuButton->setIcon(icon);
Could someone please help me figure out why my image isn't showing up and the button is just empty?
In my project using .svg images as button icons are no problem, maybe the button size is missing, try:
ui->menuButton->setIcon(QIcon(":/svg/resources/menu.svg"));
ui->menuButton->setToolTip("optional tooltip");
ui->menuButton->setFixedSize(QSize(28,28));
Assuming you stored your icons correctly in a resource file. If not, create a new:
right click on your top project folder (in the project-tree) -> Add new.. -> choose Qt on the left an Qt Resource File on the right window -> a new Window apears.
Add Prefix -> Add Files (your icon)
You use .svg image format. Are you sure your application load image format plugin for .svg? Image plugins must be in directory "imageformats" in current directory of your application. Avaliable plugins you can find in Qt directory .../Desktop/Qt/<version>/<mingw or msvc>/plugins/imageformats
I am trying to get the data from an image dragged directly from a browser to my Qt app. I have the following code:
void MyView::dropEvent( QDropEvent* event )
{
QGraphicsView::dropEvent( event );
if ( event->mimeData()->hasImage() )
{
QImage image = qvariant_cast<QImage>( event->mimeData()->imageData() );
...
This works fine with Firefox (Windows/Mac), Safari (Mac) and IE (Windows). But QMimeData::hasUrl() returns false for Chrome on both Windows and Mac.
On further investigation Qt expects image data in MIME format "application/x-qt-image". It seems that Chrome doesn't provide this. Is there a workaround for Chrome? I haven't been able to find anything.
I have a program that records video from a web camera. It shows the camera view in the form. When start button clicked it should start recording video and should be stopped after pressing stop button. Program compiles fine but no video is recorded. Can anyone say what is the wrong with it?
Here is my code.
{
camera = new QCamera(this);
viewFinder = new QCameraViewfinder(this);
camera->setViewfinder(viewFinder);
recorder = new QMediaRecorder(camera,this);
QBoxLayout *layout = new QVBoxLayout;
layout->addWidget(viewFinder);
ui->widget->setLayout(layout);
QVideoEncoderSettings settings = recorder->videoSettings();
settings.setResolution(640,480);
settings.setQuality(QMultimedia::VeryHighQuality);
settings.setFrameRate(30.0);
//settings.setCodec("video/mp4");
recorder->setVideoSettings(settings);
recorder->setContainerFormat("mp4");
camera->setCaptureMode(QCamera::CaptureVideo);
camera->start();
}
void usbrecorder::on_btn_Record_clicked()
{
usbrecorder::startRecording();
}
void usbrecorder::on_btn_Stop_clicked()
{
usbrecorder::stopRecording();
}
void usbrecorder::startRecording()
{
recorder->setOutputLocation(QUrl::fromLocalFile("C:\\Users\\Stranger\\Downloads\\Video\\vidoe_001.mp4"));
recorder->record();
}
void usbrecorder::stopRecording()
{
recorder->stop();
}
This is due to limitations on Windows.
As mentioned in Qt documentation here: https://doc.qt.io/qt-5/qtmultimedia-windows.html#limitations
Video recording is currently not supported. Additionally, the DirectShow plugin does not support any low-level video functionality such as monitoring video frames being played or recorded using QVideoProbe or related classes.
You need to specify an output location:
QMediaRecorder::setOutputLocation(const QUrl& location)
e.g.
setOutputLocation(QUrl("file:///home/user/vid.mp4"));
Try to print the state, status and error message:
qDebug()<<record.state();
qDebug()<<record.status();
qDebug()<<record.error();
and see what it prints. With those messages you can have a clear picture of your problem. Maybe QMediaRecorder cannot access your camera.
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.