 Hey everybody, this is Brian. Welcome to the 129th cute tutorial with C++ and GUI programming and if you haven't guessed by the look on your screen We're gonna start diving into the cute multimedia futures. Well, did I just say multimedia futures? I did features. I Fail at life. Sorry multimedia features It's kind of throwing me off a little bit because to do this tutorial I have my sound going out my speakers But I'm talking through my headset. So it's it's kind of a little weird sound qualities Bad, I'll redo the whole tutorial, but If you read up on the cute multimedia features You'll see there's a lot out there and you almost have to be an expert because you're actually working with low-level data types at this point We're gonna actually be covering audio and we're gonna be covering a specific type of audio And I mean just kind of go out look at some of the classes here You see they got a little bit of everything cute is actually working. I don't want to say they're working more towards But they're adding a lot of features specifically for like cell phones So you'll see a lot of things with like viewfinders and cameras and things like that which you know Radio tuners which you may or may not actually apply to the computer. You're running right now There are specific platform notes things like that. So you should really go out and Read their information before you really dive in here, but I've read it and it made actually a lot of sense so First thing we're talking about is latency and audio and latency and audio is the short period of delay usually in milliseconds between when an Audio signal enters and when it emerges from a system. And what does that really mean? Well, if you're old school like me, you remember working directly with like raw wave files and ref files Those are basically raw uncompressed audio. So it goes directly from the desk out into the speakers You know once I go to the CPU and RAM and all that Godly gook, but point being it just it's raw data. It just goes straight through whereas like an mp3 Which is what we're going to be working with today is actually like an mpg layer 3 audio codec and This gets into some of the complexities of working with Multimedia is you have different types of encoding or codecs Is they're called and if you don't have the right codec on your machine the code could work fine But you can't encode or decode depending on what you're trying to do So today, we're going to actually just make a very basic mp3 player This will be cross-platform on my Linux, but it should run in Mac Windows BSD pretty much anything So without further ado, let's crack open our trusty cute here. We're going to new project We're going to make a widgets application And you can see I've already done like a proof of concept here. We'll call it. Let's just call it my player And this is um, you know for audio audio files out there. This is going to be a very bare bones basic player We're just covering the introductory concepts here. So First thing we do here is we've got our widgets app And we need to actually include the multimedia framework in here. I Shouldn't call it a framework Multimedia library. There we go Give it a save make sure it can actually parse the file. There we go I'm Gonna try and answer some questions while we're doing this because I got to lay out the dialogue here A lot of people have been emailing me and admittedly there's just no way I can keep up with my email So I've kind of just you know scan through it and I've seen most of my emails now So I have actually seen them, but I haven't had a chance to read them all I've just been kind of scanning through the subject lines and you know Trying to figure out what you're really asking me without diving into you know, a 40 page email because I do actually get 40 page emails And I get a lot of students I don't know what's up with that, but I get a lot of hey Brian I love your videos do my homework for me and I'm sorry I just I don't have time to do your homework for you and you're in school. You should do your own homework. So Basically, what you see me laying out here is we're just going to do a volume and a progress originally, this was going to be even Basic or much is that even a word basic or much more basic than what this is But I really decided to you know beef it up a little bit Slider volume, you know, call this slider progress and so I Basically, I sound like a lunatic at the moment But what I want to reiterate here is that if you have a question join the void rums Facebook group because there's like 150 of us out there and I've seen a lot of Helping hands out there. I mean, I'm not available 24-7 and they admittedly there's people in there They're smarter than me that are helping other people out. So you've got access to a hundred and fifty experts A lot of these people literally know more than I do in specific topics. So join the void rums Facebook group and Why can't I find value? There it is derp Join the group ask your questions. It's meant to be an open community. I don't bar anybody from entering but Let's keep religion and politics out of the group. This is just strictly computers and programming So as you see we have a progress and a volume I've got the volume defaulted to 100% and we've got two buttons start and stop. So very very basic player The premise of this is obviously when you move this slider for volume the volume will go up and down when you move the progress We can you know seek through the file and it'll also move on its own as the files played So let's actually just Do a couple things here go to slot Let's do Slider moved where was it slider moved? And a lot of these you can do and the connections of signals and slots right in the objects but I really want it to be you know very easy to understand because This type of tutorial will generate probably four billion email messages, and I won't have time to go through them So I'm trying to really demystify a lot of this Okay, so Got our Q dialogue. We're gonna add in Q multimedia player and Q debug If it's Q media player, sorry about that and you can see how when you do Q media Do you get just tons and tons of stuff? I mean the the media libraries in There shouldn't call libraries the media classes in Q have just grown exponentially It's just amazing what they've done And it's not until you really get into the low-level guts of working with audio video that you can really appreciate what the developers have actually done Okay, so we've got our push button one push button to our slider clicked things like that. We're gonna actually add One more here We may add another one We're out void Duration changed I can't type today. I Really can't type today And this is going to be a Q in 64 So oh, yeah, we want to do our position change to through through the magic of copy and paste We're just gonna put another one in here now Quick explanation the position change is going to be called when the files being played through the Q media player and the position within the file Our current position has changed the duration changed is actually made it when we load the file It'll give you the the full length of the file itself There's gonna be a couple gotchas and caveats that I'll talk about at the end of the video that you'll need to be aware But we're gonna try and really keep this thing simple. All right, so we've got our base class here Let's give this compile make sure everything runs. We got little sliders. We got buttons All right, let's actually start flushing this thing out here may take me a second. Oh, yeah, you know what? I totally forgot to do something There we go, we're gonna have to actually make a variable here my bad It's like really cold here and my My voice has been kind of going in and out all day. I'm hoping I'm not getting sick I think it's just because it's really dry when I say cold. I mean the the drive to work this morning was literally negative 18 degrees. It was very cold very very cold now, there's a lot of Media objects out there. Why are we using media player? Well, we're using media player because for I want to say 90% of your tasks you're gonna either want to play a video or play an audio and both of that can be done through Q media player So rather than getting into the knit noid intricacies of each little class. We're just gonna cover these high-level classes first All right, so now that we've got our Q media player we need to connect up two signals and slots so and Remember I've warned you we're going to be doing the new method of connecting signals and slots from this point forward So we're gonna see a player if I can actually spell player and where's a Q media player And we want the position changed. We want the on position changed There we go, and we can really quickly magic of copy and paste I Call it the magic of copy and paste because some of my end users. I'm actually a network administrator. They are I'm not gonna speak ill of them, but they are challenged on a level that is just Diabolical and it will drive you crazy So I have some simple things are magic. All right, so we've got the the signals and slots connected up here Now what we need to do is actually load the file. That's gonna be the first thing push button one is where we're gonna load the file And then play it so Let's say player Yeah, and we're gonna say set media And you notice how it wants a media IO stream And it's a it's a Q media content and basically you can just give it a Q URL or Q or Q URL Did I say that right Q URL Q URL say that three times real fast and tell me it doesn't confuse you and we're gonna do from file Or I'm sorry from local file and if you're pretty savvy and you've paid attention through my networking tutorials You'll notice right away that Q URL Means you can give it a internet address and it'll actually stream the content directly from the internet Now I'm going to cheat a little bit here and I'm going to actually give it a file off my hard drive I will include this file with the source code out on My website void realms comm which usually I plug my website towards the end But I just wanted to bring it up now because when you got to tutorials and you got to you cute And then you look for this tutorial this will probably be like an eight nine meg tutorial So it'll be a bigger download But also because of the fun-loving nature of the internet and piracy I have to use a file That's not copyrighted So unfortunately, I have to use pike quite possibly the world's worst music in the history of music and you're gonna hear it here in a minute No offense to whoever well, yeah kind of offense to whoever made this music. It's horrible. Please make something better But so we're loading the file through the set media and then we're just gonna play it now a couple things are gonna happen When we do set media it's gonna fire off this duration changed and when we hit play it's gonna start seeking through that file But we also want some sort of notification If it failed to load it Which is where you know our handy Qtabug in a production system You would actually do something a little more professional than do a Qtabug And we're just gonna Qtabug out an error string A lot of times you'll see that if you lack a specific codec once again this code may run But if you don't have the right Decoder or codec it won't decode the file So there's a very real possibility that you'll download this code directly off my website and you and I just don't have the same codec At which point I'm sorry. I really I can't help you figure out which codec you need You can probably examine the properties of the mp3 file and figure it out from there But 99% of the time most modern operating systems Windows Ubuntu Mac They're all gonna have the codec to play an mp3 All right, so then our push button to is just simply We're just gonna stop playing and position changed We're say UI. Excuse me What did I call that slider progress set value and What is the name of that position and Some of you are already screaming at your monitor. I'll address that little problem here in a second All right, and during duration changed. We're gonna say UI What I call that slider volume Nope slider progress set max and Position So what we're really doing here is when the duration changed when we load the file It's gonna emit the signal which is gonna give us the maximum size of that file So we're taking that first top slider and we're saying set the maximum to whatever the maximum of the file is and then Let me go back here When the position changes aka when it's playing we're gonna set the value of that slider So you'll actually see the slider moving across the screen Now when we manually move the slider we want things to actually happen. So like slider volume here Say that four times so fast slider volume. Anyways Actually we want player sorry we want to set the volume so we're gonna set the volume of the music to the position and then the Progress when we actually move the progress slider. We want to actually player Set, I think it's set position. Yeah, set position And we're gonna, you know set the position All right, let's give this a good build And I'm actually gonna do a rebuild just because we've been playing around with us. All right, so we got a good build Let's run this and if I've done everything right you'll actually hear music All right, the world's worst music in the world. I'm sorry Now I'm gonna show you just a little bit. So like we've stopped it and we start it And we can actually You know turn the volume down and you see I'm just gonna sit here for a minute with my mouse And what's about you can actually see the progress bar moving and I'm gonna turn the volume back up and then we'll move the progress I'm sorry you had to listen to that horrible music ladies and gentlemen It's the best I could do with you know copyright free. There's a lot of starving artists out there That gentleman may continue to starve. It's just not my taste in music But anyways I'm sure if he ever heard that he'd probably sue me, but Point being that is how you play an mp3 file now. Let's talk about some troubleshooting Let's say you've run this and it doesn't work it blobbed out some error message 99% of the time you need a codec The way this works the cue media libraries, I'm sorry. I shouldn't call them libraries the cue media classes They actually used to be called phonon in q4 and I think they've just For whatever reason marketing maybe third column cue multimedia It uses an in an engine basically so you have a common platform But your operating system will obviously be different on different operating systems the elusive obvious So for example, if you're in Linux, you're probably using G streamer under the hood if you're on Mac I have honestly no clue what Mac uses If you're in Windows, I think you're using What's that called direct sound I? Think it's called direct sound Anyways, it's a derivative of direct accent. It's one of those things. I may be totally wrong But I believe that's what it uses in the hood But that's the point is that all these things have to line up your sound system has to be working your sound card has to Be installed correctly. You've got to have the right codec things like that If you download this and it doesn't work Please don't blow up my inbox because I promise you that email is gonna sit there for six seven months before I see it instead Join the Facebook group called void realms. I can't push that enough That was a pretty lengthy tutorial without a lot of code I would highly encourage you to go out and Read up on these classes, especially what we just talked about like multimedia and audio In the future if there's a lot of feedback for this I may actually talk about how to Put codecs in and how to list the codecs and things like that and we may actually expand this ability a Much more robust Multimedia player where you can do like a playlist because you can actually Write through the classes make a playlist and do random and sync and all this other stuff. It's actually really well done That's it for this tutorial. Um, I hope you found this educational and entertaining and once again join the Facebook group called void realms and if you feel so inclined go out to my website void realms calm and click on donate and just Donate any amount you feel Necessary, but if you're a starving college student, please do not donate. I don't want anybody missing a meal I could probably stand to miss a meal now. I think about it But anyways this site and all the tutorials are a hundred percent funded by your donations and myself and thousands of people around the World much appreciate it