Go Back   RunUO - Ultima Online Emulation > RunUO > Core Modifications > Other

Other Cant find a category above, use this one! Core mods not listed above go here!

Reply
 
Thread Tools Display Modes
Old 07-12-2007, 05:04 AM   #1 (permalink)
Forum Novice
 
Join Date: Aug 2003
Age: 32
Posts: 428
Send a message via MSN to aventae
Default Adding MP3player Support

Has anyone been able to successfully add in a mp3player/player support to core?

I been tinkering around with it ..just seeing if i can do it.. i did find some example code from codeproject site..but getting stuck trying to make it into a command and show up via gump controls.

Code:
/* 
 * 
 * MP3Player class provides basic functionallity for playing mp3 files.
 * Aside from the various methods it implemants events which notify their subscribers for opening files, pausing, etc.
 * This is done for boosting performance on your applications using this class, because instead of checking for info
 * on the player status over a certain time period and loosing performance, you can subscribe for an event and handle it when it fires.
 * This class also doesn't throw exceptions. The error handling is done by an event, because the probable errors which may occur are not
 * severe and the application just needs to be notified for these failures on the fly...
 * Share your source and modify this code to your heart's content, just don't change this section.
 * If you have questions, suggestions or just need to make your oppinion heard my email is krazymir@gmail.com
 * Krasimir kRAZY Kalinov 2006
 * 
 * PS: This source will only work on MS Windows, since it uses the MCI(Media Control Interface) integrated into this OS.
 * Sorry .Gnu and Mono fans! I hope soon to have enough time to get busy working on similar class for these engines...
 * 
 */

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace Media
{
    #region Event Argumenst for the events implemented by the wrapper class
    public class OpenFileEventArgs : EventArgs
    {
        public OpenFileEventArgs(string filename)
        {
            this.FileName = filename;
        }
        public readonly string FileName;
    }

    public class PlayFileEventArgs : EventArgs
    {
        public PlayFileEventArgs()
        {
        }
    }

    public class PauseFileEventArgs : EventArgs
    {
        public PauseFileEventArgs()
        {
        }
    }

    public class StopFileEventArgs : EventArgs
    {
        public StopFileEventArgs()
        {
        }
    }

    public class CloseFileEventArgs : EventArgs
    {
        public CloseFileEventArgs()
        {
        }
    }

    public class ErrorEventArgs : EventArgs
    {
        public ErrorEventArgs(long Err)
        {
            this.ErrNum = Err;
        }

        public readonly long ErrNum;
    }
    #endregion

    public class MP3Player
    {
        private string Pcommand,FName;
        private bool Opened, Playing, Paused, Loop, MutedAll, MutedLeft, MutedRight;
        private int rVolume, lVolume, aVolume, tVolume, bVolume, VolBalance;
        private ulong Lng;
        private long Err;

        [DllImport("winmm.dll")]
        private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);

        public MP3Player()
        {
            Opened = false;
            Pcommand = "";
            FName = "";
            Playing = false;
            Paused = false;
            Loop = false;
            MutedAll = MutedLeft = MutedRight = false;
            rVolume = lVolume = aVolume = tVolume = bVolume = 1000;
            Lng = 0;
            VolBalance = 0;
            Err = 0;
        }

        #region Volume
        public bool MuteAll
        {
            get
            {
                return MutedAll;
            }
            set
            {
                MutedAll = value;
                if (MutedAll)
                {
                    Pcommand = "setaudio MediaFile off";
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                }
                else
                {
                    Pcommand = "setaudio MediaFile on";
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                }
            }

        }

        public bool MuteLeft
        {
            get
            {
                return MutedLeft;
            }
            set
            {
                MutedLeft = value;
                if (MutedLeft)
                {
                    Pcommand = "setaudio MediaFile left off";
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                }
                else
                {
                    Pcommand = "setaudio MediaFile left on";
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                }
            }

        }

        public bool MuteRight
        {
            get
            {
                return MutedRight;
            }
            set
            {
                MutedRight = value;
                if (MutedRight)
                {
                    Pcommand = "setaudio MediaFile right off";
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                }
                else
                {
                    Pcommand = "setaudio MediaFile right on";
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                }
            }

        }

        public int VolumeAll
        {
            get
            {
                return aVolume;
            }
            set
            {
                if (Opened && (value >= 0 && value <= 1000))
                {
                    aVolume = value;
                    Pcommand = String.Format("setaudio MediaFile volume to {0}", aVolume);
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                }
            }
        }

        public int VolumeLeft
        {
            get
            {
                return lVolume;
            }
            set
            {
                if (Opened && (value >= 0 && value <= 1000))
                {
                    lVolume = value;
                    Pcommand = String.Format("setaudio MediaFile left volume to {0}", lVolume);
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                }
            }
        }

        public int VolumeRight
        {
            get
            {
                return rVolume;
            }
            set
            {
                if (Opened && (value >= 0 && value <= 1000))
                {
                    rVolume = value;
                    Pcommand = String.Format("setaudio MediaFile right volume to {0}", rVolume);
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                }
            }
        }

        public int VolumeTreble
        {
            get
            {
                return tVolume;
            }
            set
            {
                if (Opened && (value >= 0 && value <= 1000))
                {
                    tVolume = value;
                    Pcommand = String.Format("setaudio MediaFile treble to {0}", tVolume);
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                }
            }
        }

        public int VolumeBass
        {
            get
            {
                return bVolume;
            }
            set
            {
                if (Opened && (value >= 0 && value <= 1000))
                {
                    bVolume = value;
                    Pcommand = String.Format("setaudio MediaFile bass to {0}", bVolume);
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                }
            }
        }

        public int Balance
        {
            get
            {
                return VolBalance;
            }
            set
            {
                if (Opened && (value >= -1000 && value <= 1000))
                {
                    VolBalance = value;
                    if (value < 0)
                    {
                        Pcommand = "setaudio MediaFile left volume to 1000";
                        if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                        Pcommand = String.Format("setaudio MediaFile right volume to {0}", 1000 + value);
                        if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                    }
                    else
                    {
                        Pcommand = "setaudio MediaFile right volume to 1000";
                        if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                        Pcommand = String.Format("setaudio MediaFile left volume to {0}", 1000 - value);
                        if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                    }
                }
            }
        }
        #endregion

        #region Main Functions

        public string FileName
        {
            get
            {
                return FName;
            }
        }

        public bool Looping
        {
            get
            {
                return Loop;
            }
            set
            {
                Loop = value;
            }
        }

        public void Seek(ulong Millisecs)
        {
            if (Opened && Millisecs <= Lng)
            {
                if (Playing)
                {
                    if (Paused)
                    {
                        Pcommand = String.Format("seek MediaFile to {0}", Millisecs);
                        if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                    }
                    else
                    {
                        Pcommand = String.Format("seek MediaFile to {0}", Millisecs);
                        if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                        Pcommand = "play MediaFile";
                        if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                    }
                }
            }
        }

        private void CalculateLength()
        {
            StringBuilder str = new StringBuilder(128);
            mciSendString("status MediaFile length", str, 128, IntPtr.Zero);
            Lng = Convert.ToUInt64(str.ToString());
        }

        public ulong AudioLength
        {
            get
            {
                if (Opened) return Lng;
                else return 0;
            }
        }

        public void Close()
        {
            if (Opened)
            {
                Pcommand = "close MediaFile";
                if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                Opened = false;
                Playing = false;
                Paused = false;
                OnCloseFile(new CloseFileEventArgs());
            }
        }

        public void Open(string sFileName)
        {
            if (!Opened)
            {
                Pcommand = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
                if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                FName = sFileName;
                Opened = true;
                Playing = false;
                Paused = false;
                Pcommand = "set MediaFile time format milliseconds";
                if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                Pcommand = "set MediaFile seek exactly on";
                if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                CalculateLength();
                OnOpenFile(new OpenFileEventArgs(sFileName));
            }
            else
            {
                this.Close();
                this.Open(sFileName);
            }
        }

        public void Play()
        {
            if (Opened)
            {
                if (!Playing)
                {
                    Playing = true;
                    Pcommand = "play MediaFile";
                    if (Loop) Pcommand += " REPEAT";
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                    OnPlayFile(new PlayFileEventArgs());
                }
                else
                {
                    if (!Paused)
                    {
                        Pcommand = "seek MediaFile to start";
                        if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                        Pcommand = "play MediaFile";
                        if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                        OnPlayFile(new PlayFileEventArgs());
                    }
                    else
                    {
                        Paused = false;
                        Pcommand = "play MediaFile";
                        if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                        OnPlayFile(new PlayFileEventArgs());
                    }
                }
            }
        }

        public void Pause()
        {
            if (Opened)
            {
                if (!Paused)
                {
                    Paused = true;
                    Pcommand = "pause MediaFile";
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                    OnPauseFile(new PauseFileEventArgs());
                }
                else
                {
                    Paused = false;
                    Pcommand = "play MediaFile";
                    if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                    OnPlayFile(new PlayFileEventArgs());
                }
            }
        }

        public void Stop()
        {
            if (Opened && Playing)
            {
                Playing = false;
                Paused = false;
                Pcommand = "seek MediaFile to start";
                if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                Pcommand = "stop MediaFile";
                if((Err=mciSendString(Pcommand, null, 0, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                OnStopFile(new StopFileEventArgs());
            }
        }

        public ulong CurrentPosition
        {
            get
            {
                if (Opened && Playing)
                {
                    StringBuilder s = new StringBuilder(128);
                    Pcommand = "status MediaFile position";
                    if((Err=mciSendString(Pcommand, s, 128, IntPtr.Zero))!=0)OnError(new ErrorEventArgs(Err));
                    return Convert.ToUInt64(s.ToString());
                }
                else return 0;
            }
        }

#endregion

        #region Event Handling

        public delegate void OpenFileEventHandler(Object sender, OpenFileEventArgs oea);

        public delegate void PlayFileEventHandler(Object sender, PlayFileEventArgs pea);

        public delegate void PauseFileEventHandler(Object sender, PauseFileEventArgs paea);

        public delegate void StopFileEventHandler(Object sender, StopFileEventArgs sea);

        public delegate void CloseFileEventHandler(Object sender, CloseFileEventArgs cea);

        public delegate void ErrorEventHandler(Object sender, ErrorEventArgs eea);

        public event OpenFileEventHandler OpenFile;

        public event PlayFileEventHandler PlayFile;

        public event PauseFileEventHandler PauseFile;

        public event StopFileEventHandler StopFile;

        public event CloseFileEventHandler CloseFile;

        public event ErrorEventHandler Error;

        protected virtual void OnOpenFile(OpenFileEventArgs oea)
        {
            if (OpenFile != null) OpenFile(this, oea);
        }

        protected virtual void OnPlayFile(PlayFileEventArgs pea)
        {
            if (PlayFile != null) PlayFile(this, pea);
        }

        protected virtual void OnPauseFile(PauseFileEventArgs paea)
        {
            if (PauseFile != null) PauseFile(this, paea);
        }

        protected virtual void OnStopFile(StopFileEventArgs sea)
        {
            if (StopFile != null) StopFile(this, sea);
        }

        protected virtual void OnCloseFile(CloseFileEventArgs cea)
        {
            if (CloseFile != null) CloseFile(this, cea);
        }

        protected virtual void OnError(ErrorEventArgs eea)
        {
            if (Error != null) Error(this, eea);
        }

        #endregion
    }
}
snippet of the mp3 player code i got from codeproject.Any enlightment on this subject would be awesome.. thankx in advance.
aventae is offline   Reply With Quote
Old 07-12-2007, 07:42 AM   #2 (permalink)
Administrator
 
Zippy's Avatar
 
Join Date: Aug 2002
Location: Baltimore, MD
Age: 25
Posts: 4,870
Default

So you want the core to play music for you? Or...? I don't get what you're trying to do.
__________________
Zippy, Razor Creator and RunUO Core Developer
The RunUO Software Team

"Intuition, like a flash of lightning, lasts only for a second. It generally comes when one is tormented by a difficult decipherment and when one reviews in his mind the fruitless experiments already tried. Suddenly the light breaks through and one finds after a few minutes what previous days of labor were unable to reveal."
~The Cryptonomicon

Zippy is offline   Reply With Quote
Old 07-12-2007, 08:59 AM   #3 (permalink)
Forum Novice
 
Join Date: Aug 2003
Age: 32
Posts: 428
Send a message via MSN to aventae
Default

Quote:
Originally Posted by Zippy View Post
So you want the core to play music for you? Or...? I don't get what you're trying to do.
pretty much.. cant really do it for players dont think.. unless did some client changes... unless can do like a shoutcast thing via core...

be kinda neat to setup a shoutcast like radio station through core lol...
aventae is offline   Reply With Quote
Old 07-12-2007, 09:06 AM   #4 (permalink)
Forum Expert
 
Join Date: Dec 2005
Location: Germany
Age: 31
Posts: 401
Default

No, actually I think that would be pretty much a waste. If you want something shoutcast like, why not just set it up separately? That way you can put it on another machine, run it only when you want to, make modifications without shutting down RunUO. In contrast, I fail to see any advantages in putting shoutcast into the core.
Setharnas is offline   Reply With Quote
Old 07-12-2007, 09:52 AM   #5 (permalink)
Forum Novice
 
Join Date: Aug 2003
Age: 32
Posts: 428
Send a message via MSN to aventae
Default

Quote:
Originally Posted by Setharnas View Post
No, actually I think that would be pretty much a waste. If you want something shoutcast like, why not just set it up separately? That way you can put it on another machine, run it only when you want to, make modifications without shutting down RunUO. In contrast, I fail to see any advantages in putting shoutcast into the core.
Main reason is for the learning experience ...I dont nor have i ever went public with my shard that i run on my personal network nor will i start, So yeah this is mainly for learning experience. What i would really like to do is set up a Mp3 player client side that can load winamp playlist or the like. Just to see if it can be done with Uo. But not only would need core modification but client modification as well.. and i really havent learned reverse engineering the client to look to see if it is possible.. pretty sure that it is tho. So atm i am kinda trying to start small .. and grasp the concept of trying to add something in Core hehe.

Hope this explains lil better what i was trying to do... To you Seth aye may seem a waste of time... and maybe it is.. but the learning experience for me.. is worth the time =)
aventae is offline   Reply With Quote
Old 07-12-2007, 10:36 AM   #6 (permalink)
Forum Expert
 
Join Date: Dec 2005
Location: Germany
Age: 31
Posts: 401
Default

Yeah, I can definitely relate to the learning experience thing, no questions there. It's just that I also try to look at things from a practical point of view, and for the reasons already listed in this thread I don't really see this (mostly the client part) as starting small. Sorry if I sounded a bit condescending, that was not what I wanted.
Setharnas is offline   Reply With Quote
Old 07-12-2007, 11:58 PM   #7 (permalink)
Forum Novice
 
Join Date: Aug 2003
Age: 32
Posts: 428
Send a message via MSN to aventae
Default

Quote:
Originally Posted by Setharnas View Post
Yeah, I can definitely relate to the learning experience thing, no questions there. It's just that I also try to look at things from a practical point of view, and for the reasons already listed in this thread I don't really see this (mostly the client part) as starting small. Sorry if I sounded a bit condescending, that was not what I wanted.
np Seth, aye maybe small wasnt right word hehe.. but seems most ideas i would like to try seems to need some kinda client modification. I had already added successfuly multiple custom map support to the core, but this feature is kinda useless again without client modification. Just trying different things hehe ....
aventae is offline   Reply With Quote
Old 07-13-2007, 07:36 AM   #8 (permalink)
Forum Expert
 
Join Date: Dec 2005
Location: Germany
Age: 31
Posts: 401
Default

In that case, I wish you good luck in your attempts and am eager to see what you get out of the client for a willing community.
Setharnas is offline   Reply With Quote
Old 07-13-2007, 04:32 PM   #9 (permalink)
Forum Novice
 
Join Date: Aug 2003
Age: 32
Posts: 428
Send a message via MSN to aventae
Default

Quote:
Originally Posted by Setharnas View Post
In that case, I wish you good luck in your attempts and am eager to see what you get out of the client for a willing community.
thank you... Thought did come to mind on posiblely making this idea work ..but would be begging for the source for PlayUo ..an already modified client =P.. maybe possible to add it to that instead? ... Just a thought and a theory =)
aventae is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5