 Hey everybody, this is Brian, and welcome to the 130th Qt tutorial with C++ and GUI programming. Wow, 130 of these things. You'd think that I'd run out of things to talk about, but actually we're really just scratching the surface of what Qt can do. It's been a while. We're going to continue our conversation on the Qmedia player. It's been a while, and I've gotten some kind of like not really death threats, but just people going, hey, if you don't make another video, I will kill you. So yeah, kind of death threats. I actually went out and got my PMP certification, so yay. Video player is what we're going to name this one. And in case you haven't guessed, we're going to make, ta-da, a video player. Select Q dialog. We're doing a Q-Widget project, by the way. And we've got just our basic, you know, we've done this a million times. Now, what we need to do here is we need to add in some of the functionality. We're going to add in Multimedia and Multimedia widgets. If you've never worked with video before, you know that it can be awesome to watch, but you have no idea how to actually play a video. Video can be very frustrating. Let's give this a build real quick here. All right, so I build so we get the right headers, or the right libs in here. Video can be frustrating because you remember from our sound conversation, you need what's called a codec to decompress the data from a file and actually play the audio stream. Well, video, you actually need two codecs, the video codec and the sound codec. So I'm going to preface this whole tutorial with, if it doesn't work, try a different video. If you've tried a dozen different videos and they're still not working, try installing some codecs. All right, so we're going to include Q-Media player. And we're going to include, whoops, include not to find, geez, now I'm all messed up. My cats that I'm sure you guys have known to either love or love, one of them is dying. It's going to be a slow process. She's like 21 years old now, but she's just, she's not eating, she's not taking care of herself. So if I sound distracted, it's because I am constantly like looking at her and she's whining and stuff. She's one of those, you know, she's like a family member at this point. So I don't really want to put her down, but I'm tired of watching her suffer. All right, so we're going to make a new Q-Media player. Geez, I cannot type tonight. And we're going to make a Q-Video widget. Now you notice how I've already commented out the dialogue, because we're not going to use the dialogue for this example. I want to keep this very toned down and very simple, just because I want you to get used to understanding how to work with a video in Qt. And we're going to make a widget. I'm going to call this VW. And if this looks familiar, you've probably seen something like this or maybe this exact thing out on the internet a few dozen times. The only difference is we're really going to go over it a little bit more and try to diagnose some things. All right, so you've got a player and you've got a Q-Video widget. What's the difference between the two? Think of the Q-Media player as an artist. This is somebody with a paintbrush, and they're going to paint a picture. The Q-Video widget is the canvas they're going to paint upon. So the Q-Media player handles all the playing and decompressing and decoding of the file while the Q-Video widget is actually the medium, which the video will be displayed upon. It's a special widget, and you can't just pick any old widget. And the reason for that is it has bindings into whatever you're underlying OS uses. Like, I think Windows uses DirectShow, where some others may use GStreamer, things like that. So Qt needs to know where to point that to. Now, I should know on some platforms, like if you go to a dialog here, let me see if it's even in here. I know it was in the older ones. No, you used to find like a video where you could just drag and drop. That no longer seems to exist. I don't know where it went, but yeah. Anyway, sorry for wasting like 30 seconds of your life there. But we won't be doing that. We're going to be doing everything in memory just to keep it nice, clean, and simple. So that being said, player, we're going to set video widget, or should say set video output. Sorry, and we're going to give it the pointer to the widget that we made. Now, all that does is say, OK, Q media player, you're going to use this specific canvas. You have as many canvases as you want, but this specific player is going to paint to this canvas. Now, we're going to see, you can tell it's been a while since I've done Qt. Set media. And you notice how it's going to take a Q media constant and a QIO device and all other stuff. Well, we're just going to give it a Q URL. And you might be going, aha, you can actually send it internet links. That's true. But we're just going to do a from local file because I'm actually going to include a file that I know works. Now, I must preface this with it works on my systems. I have Windows, Linux, and Mac, and it works on all three of those kind of generic out the box. But if you have some weird version of the codec installed or you don't have the right codecs installed, you may get some funky, some funky playback or it may just not work. I'm looking at my notes because I have a special file I want to use here, MPG. Otherwise, you guys will get like a video of my cat or something like that. All right. So notice how I'm instantly what you're noticing is this is an MPG file, meaning you have to have a codec that handles MPG. This specific video, I do not believe has sound. So you probably won't hear any sound in the tutorial or on your computer, but I'm letting you know that even though it doesn't have sound, it's still going to try and locate a sound codec that's specified inside the file. So you may get some sort of warning. That's a mouthful. All right. So let's actually get in the nuts and bolts of this thing. All right. Say video widget, set geometry. You have to set the geometry. Otherwise this is going to appear as like a little tiny microscopic window that does nothing. And what this does is it sets the X position, Y position, you know, the top left corner and the width and the height. And there is ways to actually detect the video width and height which we may get into in the future tutorials. I haven't really decided how much we're going to really explore the Q media player. Now we're going to show the video widget. And if that's new to you, know that in some of especially the earlier Q tutorials, you would actually make like a Q label and you could actually show it. It would show up independently as its own little window. So if it's not already in a dialogue, it'll wrap it in a, not a Q dialogue, but in a system window and display it. Now we're going to play the video, player.play. Now you instantly notice that you, this is a slot. So aha, Qs for possibly future tutorials. You could link like a button press with play or stop or whatever you wanted to do. So they've tried to make this extremely easy and we're going to actually, just for the sake of argument here, go to a Q debug just because I like to know what is going on here. My biggest criticism about Q media player is that sometimes it gives you very little information and you're left kind of scratching your head wondering what happened. All right. So enough talking. Let's build this thing and see if it runs. Hey, it built first time. Let's run this. All right. So there is our video and you can see how we can resize the video and it kind of scales it with it. And you see how it says warning a lot of buffers are being dropped. That's actually a message from the individual codec that I have. When I ran this on Windows, I did not see that error at all. That's a video of a black hole. Yeah, it is. All right. So that kind of gives you an example of how to basically display a video. Now, some of you following along are probably going, my video did not display some troubleshooting pointers. First off, try a different video. Second, try installing the codec. How do you find the codec? That's tricky. Just because it's an MPG or an MBU or whatever it's called or an OG, I don't even know the file formats, AVI, you know, there's a billion. Just because it's one file format doesn't mean it takes one specific codec. The file format is just a container. The codec is the compression. So anyways, that's all for this tutorial. I hope you found this educational and entertaining and thank you for watching.