- MDrawer2005_source.zip
- MDrawer2005_source
- MDrawer2005_XP.zip
- MDrawer2005_XP
- MDrawer2005.sln
- MDrawer2005.suo
- MDrawer2005
- bin
- Debug
- MDrawer2005.vshost.exe
- MusicDrawer.vshost.exe
- Release
- MusicDrawer.vshost.exe
- Core
- GUI
- MDrawer2005.csproj
- obj
- Debug
- Refactor
- TempPE
- Properties.Resources.Designer.cs.dll
- MDrawer2005.csproj.FileList.txt
- Release
- Interop.WMPLib.dll
- MDrawer2005.csproj.GenerateResource.Cache
- MDrawer2005.csproj.ResolveComReference.cache
- MusicDrawer.GUI.HandleForm.resources
- MusicDrawer.GUI.MDrawerForm.resources
- MusicDrawer.Properties.Resources.resources
- Refactor
- TempPE
- Properties.Resources.Designer.cs.dll
- Program.cs
- Properties
- Resources
- 4315193766_b0c4370a27.jpg
- index.jpeg
- Thumbs.db
- Wood_floor_by_gnrbishop.jpg
- Wood-01-Patterns.jpg
- testdata
- MDrawer2005_demo.zip
- MDrawer2005_demo
- Interop.WMPLib.dll
- MusicDrawer.exe
- MDrawer2005_XP-noexe.zip
- MusicDrawer_Demo.zip
- MusicDrawer_Demo
- Interop.WMPLib.dll
- MusicDrawer.exe
- MusicDrawer.pdb
- MusicDrawer.vshost.exe
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace MusicDrawer.Core
{
//This enum will keep a track of the current status of the player
public enum PLAYER_STATUS
{
PLAYER_STATUS_NOT_READY,
PLAYER_STATUS_READY_STOPPED,
PLAYER_STATUS_PLAYING,
PLAYER_STATUS_PAUSED,
PLAYER_STATUS_ENDED,
};
//Main Wrapper class around WMPLib
class MWMPEngine
{
//Current status of the player
PLAYER_STATUS curStatus_;
//Player which will take care of playback for us
WMPLib.WindowsMediaPlayer player_ = null;
//Delegate to let the clients know about Event change
public delegate void OnStatusUpdate(PLAYER_STATUS status);
//Event for clients to subscribe to, if they want to get notfied.
public event OnStatusUpdate StatusChanged;
public MWMPEngine()
{
//create
player_ = new WMPLib.WindowsMediaPlayer();
//stupid hack
player_.settings.autoStart = false;
curStatus_ = PLAYER_STATUS.PLAYER_STATUS_NOT_READY;
player_.StatusChange += new WMPLib._WMPOCXEvents_StatusChangeEventHandler(player__StatusChange);
}
void player__StatusChange()
{
//For now just handle the "Finished" event, IF we need more we will handle more
if ("Finished" == player_.status)
{
Stop();
UpdateStatus(PLAYER_STATUS.PLAYER_STATUS_ENDED);
}
}
//This will be the first step if we want to play something
public void AttachFile(Song song)
{
if (song != null)
{
player_.currentMedia = player_.newMedia(song.PATH);
UpdateStatus(PLAYER_STATUS.PLAYER_STATUS_READY_STOPPED);
}
}
//Lets start playback
public void Play()
{
if (curStatus_ != PLAYER_STATUS.PLAYER_STATUS_PLAYING)
{
player_.controls.play();
UpdateStatus(PLAYER_STATUS.PLAYER_STATUS_PLAYING);
}
}
//Stop playback
public void Stop()
{
if (curStatus_ != PLAYER_STATUS.PLAYER_STATUS_READY_STOPPED)
{
player_.controls.stop();
UpdateStatus(PLAYER_STATUS.PLAYER_STATUS_READY_STOPPED);
}
}
//Pause playback
public void Pause()
{
if (curStatus_ != PLAYER_STATUS.PLAYER_STATUS_PAUSED)
{
player_.controls.pause();
UpdateStatus(PLAYER_STATUS.PLAYER_STATUS_PAUSED);
}
}
//Resume playback
public void Resume()
{
if (curStatus_ == PLAYER_STATUS.PLAYER_STATUS_PAUSED)
{
player_.controls.play();
UpdateStatus(PLAYER_STATUS.PLAYER_STATUS_PLAYING);
}
}
//UI can call this function to keep itself up to date
public PLAYER_STATUS GetPlayerstatus()
{
return curStatus_;
}
//Duration of current item
public double Duration
{
get
{
return player_.controls.currentItem.duration;
}
}
//HUman readable duration string
public string DurationString
{
get
{
return player_.controls.currentItem.durationString;
}
}
//Current play position
public double CurruntPosition
{
get
{
return player_.controls.currentPosition;
}
set //Set current position, perhaps from seekbar of UI
{
player_.controls.currentPosition = value;
}
}
//Human readable current play position
public string CurruntPositionString
{
get
{
return player_.controls.currentPositionString;
}
}
//Update the UI with new status of player
private void UpdateStatus(PLAYER_STATUS status)
{
curStatus_ = status;
StatusChanged(curStatus_);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I Started my Programming career with C++. Later got a chance to develop Windows Form applications using C#. Currently using C#, ASP.NET & ASP.NET MVC to create Information Systems, e-commerce/e-governance Portals and Data driven websites.
My interests involves Programming, Website development and Learning/Teaching subjects related to Computer Science/Information Systems. IMO, C# is the best programming language and I love working with C# and other Microsoft Technologies.
- Microsoft Certified Technology Specialist (MCTS): Web Applications Development with Microsoft .NET Framework 4
- Microsoft Certified Technology Specialist (MCTS): Accessing Data with Microsoft .NET Framework 4
- Microsoft Certified Technology Specialist (MCTS): Windows Communication Foundation Development with Microsoft .NET Framework 4
If you like my articles, please visit my website for more: www.rahulrajatsingh.com[^]