I am developing a media player using vlc-qt I wanted to know how can I identify that my player contains a video or not.
For example
m_player=new VlcMediaPlayer(m_instance);
m_media= new VlcMedia("",m_instance);
m_player->open(m_media);
m_player->play()
As you can see here my m_media is initialized with no video url so how can I check whether my m_media contains any video or not.
I wanted to know this because so that in my player i will control play/stop button.
Solution
After opening the media use VlcMediaPlayer::video to retrieve the video object and check if it is valid, i.e. not a nullptr.
Example
Here is an example I wrote for you to demonstrate a possible implementation of the proposed solution:
m_player = new VlcMediaPlayer(m_instance);
m_media = new VlcMedia("", m_instance);
m_player->open(m_media);
if (m_player->video())
m_player->play();
According to VlcMedia source, the string you give to the class can be retrieved using the getter VlcMedia::currentLocation(). From that string, you can use QFile::exists() to check if the file path exists.
Related
I want to access the metadata of the mp3 file and put it in the labels but the program doesn't read it.
I read http://doc.qt.io/qt-5/qmediametadata.html.
I wrote this code but it doesn't work properly (besides QFileInfo).
path = item->text(); //text is a path from QFileDialog::getOpenFileName
/*QMediaPlayer*/ sound.setMedia(QUrl::fromLocalFile(path));
QFileInfo info(path);
ui->label_3->setText(sound.metaData("Title").toString());
if (ui->label_3->text()=="")
ui->label_3->setText(sound.metaData("AlbumTitle").toString());
if (ui->label_3->text()=="")
ui->label_3->setText(info.baseName());
ui->label_5->setText(sound.metaData("Author").toString());
if (ui->label_5->text()=="")
ui->label_5->setText(sound.metaData("AlbumArtist").toString());
if (ui->label_5->text()=="")
ui->label_5->setText(sound.metaData("Composer").toString());
Library and multimedia are added.
Cause
It takes time for the media to be loaded after calling QMediaPlayer::setMedia, hence requesting the meta data right after the media has been set results in:
QVariant(Invalid)
Solution
I would suggest you to wait for the media to be loaded by connecting to the QMediaPlayer::mediaStatusChanged and reading the meta data once the status becomes QMediaPlayer::LoadedMedia.
Note: If you make sound a local variable, it would be destroyed when it goes out of scope. Better use auto *sound = new QMediaPlayer(this);.
Example
Here is an example I have prepared for you of how you could change your code in order to implement to proposed solution:
connect(sound, &QMediaPlayer::mediaStatusChanged, [this, sound, info](QMediaPlayer::MediaStatus status){
if (status == QMediaPlayer::LoadedMedia) {
ui->label_3->setText(sound->metaData("Title").toString());
if (ui->label_3->text()=="")
ui->label_3->setText(sound->metaData("AlbumTitle").toString());
if (ui->label_3->text()=="")
ui->label_3->setText(info.baseName());
ui->label_5->setText(sound->metaData("Author").toString());
if (ui->label_5->text()=="")
ui->label_5->setText(sound->metaData("AlbumArtist").toString());
if (ui->label_5->text()=="")
ui->label_5->setText(sound->metaData("Composer").toString());
}
});
I've been working on a simple map editor tool for a game project in pygame. Right now I'm trying to have the program load all the images from a specific folder when it launches. For each image I create a file in a list, and make that into a custom class object. It is assigned a .fileImage value when I add it as a class object.
The error: Couldn't open E:\Pygame Engine Test\Assets\\Blocks\coldstoneWideBrick.png
I only don't understand this error because I've tried debugging the problem for a while now and it makes no sense.
When I load in the image I do this:
class editorBlocks:
def __init__(self, Image, Name, Type):
self.editName = Name
self.fileImage = pygame.image.load(blockDir + Image).convert()
self.obType = Type
If I have the program enter "coldstoneWideBrick.png" as the Image value for the class, it returns the above error. I've tried printing Image when I input it and get it "coldstoneWideBrick.png". However, if I replace the line that loads the image with this:
self.fileImage = pygame.image.load(blockDir + "coldstoneWideBrick.png").convert()
It loads the image without error. Why is it that it only has difficulty when I have it use the Image input, even though the input has an identical value?
After some further review of the problem, I noticed that when i printed in the value there was a blank line after it every time.
I was able to fix it by changing how I loaded in the image value (it was loaded from a file before put into a class.) Sorry for making such a simple mistake and thanks for your time!
I'm using a simple numeric text validator wxTextValidator along with a wxTextControl. I wonder what the 2nd parameter is good for:
wxTextValidator(long style = wxFILTER_NONE, wxString* valPtr = NULL)
I simply passed the reference to a member variable:
myTextControl_->SetValidator( wxTextValidator(wxFILTER_NUMERIC, &myValue_) );
I'm using wxWidgets 2.8.12, from the documentation I figured that the myValue_ variable would receive the validated content of the text control, but this does not happen in my application.
Am I doing something wrong or does the valPtr parameter not receive the content of the text control?
The myvalue_ variable should receive the value entered if you call wxValidator::Validate or wxValidator::TransferFromWindow. This happens automatically if you close the dialog with the default OnOK() handler. Otherwise you have to do it yourself.
Ravenspoint has already answered the initial question but I'd just like to add that wxValidator can be used either for validating or for data transfer -- or for both at once. In fact, some validators, such as wxGenericValidator are only used for data transfer (it doesn't make much sense to validate a check box or a radio button!). So the name of this class is somewhat misleading as it describes at most half, and probably less than that, of its uses.
I'm currently working on a "save" mechanism, which allows a user to save the project his working on on hard disc. The output will be a XML file containing all kinds of data.
Now our project structure is about to change and we need to write a new xml file (create a new save method).
So now here comes the challenge: When saving I want the user to be able to choose which file format he will be creating (version1 (old) or version2 (new)).
Does anyone now how to achieve that? Is there a suitable design pattern around?
Remarks:
- The data we are saving can be seen as unrelated blocks, so it would actually be easy to exchange an old block with a new one.
- The whole goal of the thing is, it should be readable again when loading an old project. (I assume this can be done by tags, and just react on tags when loading?)
This sounds like a good application for the Strategy pattern.
You would create an abstract base class FileFormat (the Strategy interface) with two virtual functions, projectToXml and xmlToProject, which are supposed to turn your internal project representation into XML or vice versa.
Then you create two implementing subclasses FileFormatNew and FileFormatLegacy (these are the concrete strategies).
Your save functions would then additionally require an instance of FileFormat, and call the corresponding method of that object to do the data conversion. Your load function could choose the strategy to use by examining the XML tree for something which tells it which version it is.
And when you ever need to support another file format, you just have to create a new class which is a subclass of FileFormat.
Addendum after the exchange in the comments
When you are going to have a lot of versions with very small differences and you still want to use the Strategy pattern, you could make the FileFormat a composite of multiple strategies: A CircleStragegy, a RectangleStrategy, a LineStrategy etc.. In that case I wouldn't use different classes for different versions of the FileFormat. I would create a static factory function for each version which returns a FileFormat with the Strategy objects used in that version.
FileFormat FileFormat::createVersion1_0() {
return new FileFormat(
new LineStrategyOld(),
new CircleStrategyOld(),
new RectangleStragegyOld()
);
}
FileFormat FileFormat::createVersion1_1() {
// the 1.1 version introduced the new way to save lines
return new FileFormat(
new LineStrategyNew(),
new CircleStrategyOld(),
new RectangleStragegyOld()
);
}
FileFormat FileFormat::createVersion1_2() {
// 1.2 uses the new format to save circles
return new FileFormat(
new LineStrategyNew(),
new CircleStrategyNew(),
new RectangleStragegyOld()
);
}
FileFormat FileFormat::createVersion1_3() {
// 1.3 uses a new format to save rectangles, but we realized that
// the new way to save lines wasn't that good after all, so we
// returned to the old way.
return new FileFormat(
new LineStrategyOld(),
new CircleStrategyNew(),
new RectangleStragegyNew()
);
}
Note: In real code you would of course use more descriptive suffixes than "Old" and "New" for your strategy class names.
What I'm trying to do is to fill ListView in Windows 8 Metro application dynamically with pre-loaded images.
for each item (URI) I'm doing it plain simple with the code like this (C++):
Windows::UI::Xaml::Media::Imaging::BitmapImage^ bitmapSrc =
ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
bitmapSrc->CreateOptions = Windows::UI::Xaml::Media::Imaging::BitmapCreateOptions::IgnoreImageCache;
bitmapSrc->UriSource = uri;
img->Source = bitmapSrc;
LoadListView->Items->Append(img);
but when I delete (in the app) source image described by URI and I create new file with the same name and try to reload it into the list then I fail and image shown is the old one (deleted). I presume some cache works here. I tried to avoid caching by IgnoreImageCache value in CreateOptions but it didn't work.
Any clues how to disable caching of BitmapSource (Image) potentially bound to ListView in Windows 8 app?
I tried several directions inspired by Silverlight and WPF, none worked unfortunately.
Encouraged by comments, I put answer I've found myself.
Broader context (and also C# perspective) is explained here:
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/171dfe66-78b5-4340-bd78-244337f31287/
Shortly I believe it's a problem with reference counting here.
WinRT keeps the image loaded (cached) in BitmapImage^ as long as Uri is valid and asigned to the object instance, that in my example is added to the list.
Cleaning Uri from BitmapImage^ prior to releasing it from the list solved problem in my case.
According to example in question, below code solves the problem (included in the part where the list removal is performed):
auto item = (Image^)LoadListView->Items->GetAt(selected);
auto src = (Windows::UI::Xaml::Media::Imaging::BitmapImage^)item->Source;
src->UriSource = nullptr; //this line is critical
LoadListView->Items->RemoveAt(selected);