An OOP Question

Deque

Limp Gawd
Joined
Jun 1, 2004
Messages
484
I have a wrapper around the DirectX.AudioVideoPlayback DLL

The services I want my wrapper to perform are:

Code:
class Music{
    Play();
    Play(int index);
    Stop();
    Pause();
    Mute();
    SetVolume(int value);
    UnMute(); 
    ... 
    ...
}
I then have my main class which contains all the WinForms code.
Code:
class MusicPlayer{
    private Music m;

    public void next(){
        m.Next();
        
        // other GUI Code
    }
}


My dilemma. I added an EventHandler for when the music file has stopped playing in my wrapper class (Music), the only problem is that my main class (lets call it MusicPlayer) needs to know when the current song has stopped playing, because it needs to update various components of the GUI (I have a label for current running time, a slider calculating the current time in relation to the beginning and end, etc)

So I'm confused on how to get MusicPlayer to know when the song has ended so it can update the current time/running time control on the Windows Form. (This would be in the format "03:25 / 06:02", sort of like how Windows Media Player does.)




----------------------------------------------------------------------------------------------------------------------
Edit: I actually figured it out while I was typing this post out.

The problem is that I'm calculating the running time of the song in the GUI class (MusicPlayer) when technically that should be an aspect of the Wrapper Class. So I am going to move all my timers calculating running time to the Music class, add a public function that returns the currentRunningTime, then add another timer to my MusicPlayer class that just polls the currentRunningTime() function and updates the controls on the WinForm.

This way, I can make my Audio variable (from the DirectX DLL) private, and add my EventHandlers to the Music Class.

The only problem I forsee is that you actually lose functionality with the wrapper class by making the wrapper class always perform a pre-determined set of instructions at the end of every song.

I think I need to read up on abstraction and virtual functions and inheritance, although I may be wrong in my assumption. The only reason I guess I've had a hard time getting a hold on abstraction/virtual functions/inheritance, is that I've never actually used it before - so maybe this project will give me a reason to read up on it.

If anyone wants to point out flaws in my logic, or at least point me in the right direction....please do so! I'm a relative OOP newbie, so anything you can teach me would be greatly appreciated.

Also, I apologize if my post makes absolutely 0 sense. Also, if anyone is curious....the project I wrote was basically a WinAMP clone. It doesn't do anything revolutionary, I just wanted to dabble in a project that can help teach me C# and understanding DLL's a little bit more. (Before I started using DirectX for my music playback, I was using Quartz.DLL, but I ran into some problems with playback with that)
 
Back
Top