Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

BSEtunes

, 24 Apr 2010 CPOL
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
BSE.Platten.zip
BSE.Platten
BSE.Platten.vssscc
mssccprj.scc
vssver2.scc
BSE.CoverFlow.WPFLib
BSE.CoverFlow.WPFLib.csproj.user
BSE.CoverFlow.WPFLib.csproj.vspscc
mssccprj.scc
vssver2.scc
Images
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
vssver2.scc
BSE.Platten.Admin
BSE.Platten.Admin.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp
BSE.Platten.Admin.WinApp.csproj.user
BSE.Platten.Admin.WinApp.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
BSEadmin.ico
vssver2.scc
BSE.Platten.Audio
bse.ico
BSE.Platten.Audio.csproj.vspscc
mssccprj.scc
vssver2.scc
Options
vssver2.scc
Player
vssver2.scc
Properties
vssver2.scc
Resources
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
WinControls
vssver2.scc
WMFSDK
vssver2.scc
BSE.Platten.BO
BSE.Platten.BO.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Common
BSE.Platten.Common.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers
BSE.Platten.Covers.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
vssver2.scc
BSE.Platten.FreeDb
BSE.Platten.FreeDb.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
vssver2.scc
BSE.Platten.Ripper
BSE.Platten.Ripper.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik
BSE.Platten.Statistik.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Tunes
BSE.Platten.Tunes.csproj.user
BSE.Platten.Tunes.csproj.vspscc
mssccprj.scc
vssver2.scc
Filters
vssver2.scc
Properties
Settings.settings
vssver2.scc
Resources
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup
BSEadminSetup.vdproj
BSEadminSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
BSEtunesSetup
BSEtunesSetup.vdproj
BSEtunesSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
dll
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.Windows.Forms.DLL
Lame
lame_enc.dll
vssver2.scc
lame-3.97
BSE.Platten_en.zip
BSE.CoverFlow.WPFLib.csproj.user
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
Settings.settings
vssver2.scc
vssver2.scc
BSE.Platten.Admin.csproj.user
Settings.settings
vssver2.scc
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp.csproj.user
Settings.settings
vssver2.scc
BSEadmin.ico
vssver2.scc
bse.ico
BSE.Platten.Audio.csproj.user
vssver2.scc
vssver2.scc
vssver2.scc
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
vssver2.scc
vssver2.scc
BSE.Platten.BO.csproj.user
vssver2.scc
BSE.Platten.Common.csproj.user
vssver2.scc
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers.csproj.user
Settings.settings
vssver2.scc
BSE.Platten.FreeDb.csproj.user
vssver2.scc
OpenCD.png
vssver2.scc
AudioWriter
vssver2.scc
BSE.Platten.Ripper.csproj.user
Lame
vssver2.scc
vssver2.scc
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik.csproj.user
vssver2.scc
BSE.Platten.Tunes.csproj.user
vssver2.scc
Settings.settings
vssver2.scc
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup.vdproj
BSEtunesSetup.vdproj
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.ThreadedShell.DLL
BSE.Windows.Forms.DLL
lame_enc.dll
MySQL.chm.zip
MySQL.chm
MySqlCreateDataBase5x.sql.zip
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using BSE.Platten.Audio.Properties;

namespace BSE.Platten.Audio
{
    public class MediaPlayer : Player
    {
        #region FieldsPrivate

        private WMPLib.WindowsMediaPlayer m_mediaPlayer;
        private WMPLib.WMPPlayState m_ePlayState;
        private int m_iTrackPosition;

        #endregion

        #region Properties
        /// <summary>
        /// The count property retrieves the number of media items in the playlist.
        /// </summary>
        public override int Count
        {
            get { return this.m_mediaPlayer.currentPlaylist.count; }
        }
        /// <summary>
        /// Gets the name of the used audioplayer
        /// </summary>
        public override string Name
        {
            get { return "Microsoft MediaPlayer"; }
        }
        #endregion

        #region MethodsPublic

        public MediaPlayer()
        {
            this.m_mediaPlayer = new WMPLib.WindowsMediaPlayer();
            this.m_mediaPlayer.settings.autoStart = false;
            this.m_mediaPlayer.settings.setMode("autoRewind", false);
            this.m_mediaPlayer.settings.playCount = 1;
            this.m_mediaPlayer.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(PlayStateChange);
        }
        /// <summary>
        /// Causes the media item to start playing.
        /// </summary>
        public override void Play()
        {
            this.m_mediaPlayer.controls.play();
        }
        /// <summary>
        /// Causes the media item to start playing.
        /// </summary>
        /// <param name="strFile">A string containing the full path of the media file</param>
        /// <param name="mode">the mode for playing</param>
        public override void Play(string strFile, BSE.Platten.Audio.PlayMode mode)
        {
            this.Mode = mode;
            ClearPlayList();
            try
            {
                if (CCheckFile.FileExists(strFile) == true)
                {
                    WMPLib.IWMPMedia wmpMedia = this.m_mediaPlayer.newMedia(strFile);
                    this.m_mediaPlayer.currentPlaylist.insertItem(0, wmpMedia);
                    if (this.m_mediaPlayer.currentPlaylist.count > 0)
                    {
                        this.m_mediaPlayer.controls.play();
                    }
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                throw;
            }
        }
        /// <summary>
        /// Causes the media items to start playing.
        /// </summary>
        /// <param name="strFiles">A string[] containing the full path of the media files</param>
        /// <param name="mode">the mode for playing</param>
        public override void Play(string[] strFiles, BSE.Platten.Audio.PlayMode mode)
        {
            if (strFiles == null)
            {
                throw new ArgumentNullException(
                    string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.IDS_ArgumentNullException, "strFiles"));
            }
            this.Mode = mode;
            int iFileCount = strFiles.Length;
            string[] files = strFiles;

            ClearPlayList();

            for (int i = 0; i < iFileCount; i++)
            {
                string fileName = files[i];
                try
                {
                    if (CCheckFile.FileExists(fileName) == true)
                    {
                        WMPLib.IWMPMedia wmpMedia = this.m_mediaPlayer.newMedia(fileName);
                        this.m_mediaPlayer.currentPlaylist.appendItem(wmpMedia);
                    }
                }
                catch (System.IO.FileNotFoundException)
                {
                    throw;
                }
            }
            if (this.m_mediaPlayer.currentPlaylist.count > 0)
            {
                this.m_mediaPlayer.controls.play();
            }
        }
        /// <summary>
        /// Not used in Windows Media Player
        /// </summary>
        public override void Load()
        {
        }
        /// <summary>
        /// Releases Windows Media Player resources.
        /// </summary>
        public override void Close()
        {
            this.m_mediaPlayer.PlayStateChange -= new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(PlayStateChange);
            OnPlayerClosed(this,new PlayerEventArgs(this.Mode));
            this.m_mediaPlayer.close();
        }
        /// <summary>
        /// The pause method pauses playback of the media item.
        /// </summary>
        public override void Pause()
        {
            this.m_mediaPlayer.controls.pause();
        }
        /// <summary>
        /// The stop method stops playback of the media item.
        /// </summary>
        public override void Stop()
        {
            this.Mode = PlayMode.None;
            this.m_mediaPlayer.controls.stop();
        }
        /// <summary>
        /// Gets the new position in the playlist.
        /// </summary>
        /// <returns>current playlist position</returns>
        public override int GetPlaylistPosition()
        {
            int iPlayListPosition = 0;
            int iCount = this.m_mediaPlayer.currentPlaylist.count;
            if (iCount > 0)
            {
                for (int i = 0; i < iCount; i++)
                {
                    WMPLib.IWMPMedia wmpMedia = this.m_mediaPlayer.currentPlaylist.get_Item(i);
                    if (this.m_mediaPlayer.controls.currentItem.get_isIdentical(wmpMedia))
                    {
                        iPlayListPosition = i;
                        break;
                    }
                }
            }
            return iPlayListPosition;
        }
        /// <summary>
        /// Sets the new position in the playlist.
        /// </summary>
        /// <param name="iPosition">new playlist position</param>
        public override void SetPlaylistPosition(int iPosition)
        {
            if (iPosition >= 0 && iPosition < this.Count)
            {
                WMPLib.IWMPMedia wmpMedia = this.m_mediaPlayer.currentPlaylist.get_Item(iPosition);
                this.m_mediaPlayer.controls.playItem(wmpMedia);
            }
        }
        /// <summary>
        /// Removes the content of the playlist
        /// </summary>
        public override void ClearPlayList()
        {
            this.m_mediaPlayer.currentPlaylist.clear();
        }
        /// <summary>
        /// Sets the current position in the media item in seconds from the beginning.
        /// </summary>
        /// <param name="iCurrentPostion">current position in seconds</param>
        public override void SetTrackPosition(int iCurrentPostion)
        {
            if (iCurrentPostion > 0)
            {
                double dCurrentPosition = Convert.ToDouble(iCurrentPostion);
                this.m_mediaPlayer.controls.currentPosition = dCurrentPosition;
            }
        }
        /// <summary>
        /// Gets the current position in the media item in seconds from the beginning.
        /// </summary>
        /// <returns>current position in seconds</returns>
        public override int GetTrackPosition()
        {
            try
            {
                if (this.m_ePlayState != WMPLib.WMPPlayState.wmppsTransitioning)
                {
                    this.m_iTrackPosition = Convert.ToInt32(this.m_mediaPlayer.controls.currentPosition);
                }
            }
            catch
            {
                //throw new Exception("MediaPlayer GetTrackPosition Playstate" + this.m_ePlayState.ToString());
            }
            return this.m_iTrackPosition;
        }
        /// <summary>
        /// Gets the duration in seconds of the current media item
        /// </summary>
        /// <returns>the duration in seconds</returns>
        public override int GetTrackLength()
        {
            return Convert.ToInt32(this.m_mediaPlayer.currentMedia.duration);
        }

        public override string GetSongTitle()
        {
            string strAuthor = this.m_mediaPlayer.currentMedia.getItemInfo(WMFSDK.WM.g_wszWMAuthor);
            string strTitle = this.m_mediaPlayer.currentMedia.getItemInfo(WMFSDK.WM.g_wszWMTitle);
            if ((String.IsNullOrEmpty(strAuthor) == false) && (String.IsNullOrEmpty(strTitle) == false))
            {
                return strAuthor + " - " + strTitle;
            }
            else
            {
                return UnknownTitle;
            }
        }

        #endregion

        #region MethodsPrivate

        private void PlayStateChange(int playState)
        {
            WMPLib.WMPPlayState ePlayState = (WMPLib.WMPPlayState)playState;
            this.m_ePlayState = ePlayState;
            this.PlayState = PlayState.Undefined;
            switch (ePlayState)
            {
                case WMPLib.WMPPlayState.wmppsReady:
                    //Wird keine Playlist (nicht Mode.CD, alle anderen Modi) abgespielt..
                    if ((this.Mode == PlayMode.Playlist) || (this.Mode == PlayMode.Random) || (this.Mode == PlayMode.Song))
                    {
                        //soll der Player weiterlaufen
                        this.m_mediaPlayer.controls.play();
                    }
                    break;
                case WMPLib.WMPPlayState.wmppsMediaEnded:
                    this.PlayState = PlayState.Ended;
                    if (this.Mode != PlayMode.CD)
                    {
                        OnSongEnded(this, new PlayerEventArgs(this.Mode));
                    }
                    else
                    {
                        //Ist der zuletzt beendete Track identisch mit dem letzten Track in
                        //der Playlist wird der Player gestoppt
                        WMPLib.IWMPMedia wmpMedia = this.m_mediaPlayer.currentPlaylist.get_Item(this.Count - 1);
                        if (this.m_mediaPlayer.controls.currentItem.get_isIdentical(wmpMedia) == true)
                        {
                            OnPlayerStopped(this, new PlayerEventArgs(this.Mode));
                        }
                    }
                    break;
                case WMPLib.WMPPlayState.wmppsStopped:
                    this.PlayState = PlayState.Stopped;
                    OnPlayerStopped(this, new PlayerEventArgs(this.Mode));
                    break;
                case WMPLib.WMPPlayState.wmppsPlaying:
                    this.PlayState = PlayState.Playing;
                    OnPlayerPlays(this, new PlayerEventArgs(this.Mode));
                    break;
                case WMPLib.WMPPlayState.wmppsPaused:
                    this.PlayState = PlayState.Paused;
                    OnPlayerPaused(this, new PlayerEventArgs());
                    break;
            }
        }
        
        #endregion
    }
}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Uwe Eichkorn

Switzerland Switzerland
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411023.1 | Last Updated 24 Apr 2010
Article Copyright 2009 by Uwe Eichkorn
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid