示例#1
0
 public OggPlayer()
 {
     m_BufferSize = 4096;
     m_Buffers = new uint[32];
     m_PlayerState = OggPlayerStatus.Waiting;
     InitSource();
 }
示例#2
0
 protected void StateChange(OggPlayerStatus NewState, OggPlayerStateChanger Reason)
 {
     if (StateChanged != null)
     {
         StateChanged(this, new OggPlayerStateChangedArgs(m_PlayerState, NewState, Reason));
     }
                 #if (DEBUG)
     Console.WriteLine(DateTime.Now.ToLongTimeString() + "\tOggPlayer::StateChange -- From: " + OggUtilities.GetEnumString(m_PlayerState) + " -- To: " + OggUtilities.GetEnumString(NewState));
                 #endif
     m_PlayerState = NewState;
 }
示例#3
0
        /// <summary>
        /// Converts an enumeration into a description string for display to a user
        /// </summary>
        /// <param name="opStatus">
        /// An <see cref="OggPlayerStatus"/> enumeration to interpret
        /// </param>
        /// <returns>
        /// A <see cref="System.String"/> containing the description
        /// </returns>
        static public string GetEnumString(OggPlayerStatus opStatus)
        {
            switch (opStatus)
            {
            case OggPlayerStatus.Buffering: return("Buffering");

            case OggPlayerStatus.Error: return("Player Error");

            case OggPlayerStatus.Paused: return("Paused");

            case OggPlayerStatus.Playing: return("Playing");

            case OggPlayerStatus.Seeking: return("Seeking");

            case OggPlayerStatus.Stopped: return("Stopped");

            case OggPlayerStatus.Waiting: return("Waiting for file");

            default: return("Unknown Player Status Value");
            }
        }
示例#4
0
 /// <summary>
 /// Converts an enumeration into a description string for display to a user
 /// </summary>
 /// <param name="opStatus">
 /// An <see cref="OggPlayerStatus"/> enumeration to interpret
 /// </param>
 /// <returns>
 /// A <see cref="System.String"/> containing the description
 /// </returns>
 public static string GetEnumString(OggPlayerStatus opStatus)
 {
     switch (opStatus)
     {
     case OggPlayerStatus.Buffering: return "Buffering";
     case OggPlayerStatus.Error: return "Player Error";
     case OggPlayerStatus.Paused: return "Paused";
     case OggPlayerStatus.Playing: return "Playing";
     case OggPlayerStatus.Seeking: return "Seeking";
     case OggPlayerStatus.Stopped: return "Stopped";
     case OggPlayerStatus.Waiting: return "Waiting for file";
     default: return "Unknown Player Status Value";
     }
 }
示例#5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="eOldState">
 /// Original state of the player as an <see cref="OggPlayerStatus"/> enumeration
 /// </param>
 /// <param name="eNewState">
 /// New state of the player as an <see cref="OggPlayerStatus"/> enumeration
 /// </param>
 /// <param name="eChanger">
 /// Reason for the change in state as an <see cref="OggPlayerStateChanger"/> enumeration
 /// </param>
 public OggPlayerStateChangedArgs(OggPlayerStatus eOldState, OggPlayerStatus eNewState, OggPlayerStateChanger eChanger)
 {
     m_OldState = eOldState; m_NewState = eNewState; m_Changer = eChanger;
 }
示例#6
0
 protected void StateChange(OggPlayerStatus NewState, OggPlayerStateChanger Reason)
 {
     if (StateChanged!=null) { StateChanged(this, new OggPlayerStateChangedArgs(m_PlayerState, NewState, Reason)); }
     #if (DEBUG)
         Console.WriteLine(DateTime.Now.ToLongTimeString() + "\tOggPlayer::StateChange -- From: " + OggUtilities.GetEnumString(m_PlayerState) + " -- To: " + OggUtilities.GetEnumString(NewState));
     #endif
     m_PlayerState = NewState;
 }
示例#7
0
 protected void StateChange(OggPlayerStatus NewState)
 {
     StateChange(NewState, OggPlayerStateChanger.Internal);
 }
示例#8
0
 protected void StateChange(OggPlayerStatus NewState)
 {
     StateChange(NewState, OggPlayerStateChanger.Internal);
 }
示例#9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="eOldState">
 /// Original state of the player as an <see cref="OggPlayerStatus"/> enumeration
 /// </param>
 /// <param name="eNewState">
 /// New state of the player as an <see cref="OggPlayerStatus"/> enumeration
 /// </param>
 /// <param name="eChanger">
 /// Reason for the change in state as an <see cref="OggPlayerStateChanger"/> enumeration
 /// </param>
 public OggPlayerStateChangedArgs(OggPlayerStatus eOldState, OggPlayerStatus eNewState, OggPlayerStateChanger eChanger)
 {
     m_OldState = eOldState; m_NewState = eNewState; m_Changer = eChanger;
 }
示例#10
0
 private void StateChange(OggPlayerStatus NewState, OggPlayerStateChanger Reason)
 {
     if (StateChanged != null) { StateChanged(this, new OggPlayerStateChangedArgs(m_PlayerState, NewState, Reason)); }
     m_PlayerState = NewState;
 }
示例#11
0
 private void StateChange(OggPlayerStatus NewState)
 {
     StateChange(NewState, OggPlayerStateChanger.Internal);
 }
示例#12
0
        /**
         *  funkcja odpalana na oddzielnym w¹tku
         */
        private void PlayThread()
        {
            bool Running = true; bool ReachedEOF = false; bool UnderRun = false;
            while (Running)
            {
                if (m_PlayerState == OggPlayerStatus.Playing)
                {
                    int QueuedBuffers = 0;
                    AL.GetSource(m_Source, ALGetSourcei.BuffersQueued, out QueuedBuffers);
                    if (ReachedEOF)
                    {
                        if (QueuedBuffers > 0) { }
                        else
                        {
                            lock (OALLocker)
                            {
                                Running = false;
                                if (AL.GetSourceState(m_Source) != ALSourceState.Stopped) { AL.SourceStop(m_Source); }
                                m_CurrentFile.ResetFile();

                                for (int i = 0; i < m_Buffers.Length; i++)
                                {
                                    AL.DeleteBuffer(ref m_Buffers[i]);
                                }
                                m_Buffers = new uint[32];
                            }
                            StateChange(OggPlayerStatus.Stopped, OggPlayerStateChanger.EndOfFile);
                            return;
                        }
                    }

                    if ((!ReachedEOF) && (QueuedBuffers > 0) && (AL.GetError() == ALError.NoError))
                        if (AL.GetSourceState(m_Source) != ALSourceState.Playing)
                            AL.SourcePlay(m_Source);

                    int ProcessedBuffers = 0;
                    uint BufferRef = 0;
                    lock (OALLocker)
                    {
                        AL.GetSource(m_Source, ALGetSourcei.BuffersProcessed, out ProcessedBuffers);
                    }
                    if (ProcessedBuffers >= 32) UnderRun = true;
                    else UnderRun = false;

                    while (ProcessedBuffers > 0)
                    {
                        OggBufferSegment obs;
                        lock (OALLocker)
                        {
                            AL.SourceUnqueueBuffers(m_Source, 1, ref BufferRef);
                            if (ReachedEOF) { --ProcessedBuffers; continue; }	// If we're at the EOF loop to the next buffer here - we don't want to be trying to fill any more
                            obs = m_CurrentFile.GetBufferSegment(m_BufferSize);	// Get chunk of tasty buffer data with the configured segment
                        }

                        if (obs.ReturnValue > 0)
                        {
                            lock (OALLocker)
                            {
                                AL.BufferData((int)BufferRef, m_CurrentFile.Format, obs.Buffer, obs.ReturnValue, obs.RateHz);
                                AL.SourceQueueBuffers(m_Source, 1, ref BufferRef);
                            }
                        }
                        else
                        {
                            if (obs.ReturnValue == 0) { ReachedEOF = true; break; }
                            else
                            {
                                lock (OALLocker)
                                {
                                    m_PlayerState = OggPlayerStatus.Error;
                                    AL.SourceStop(m_Source);
                                    Running = false;
                                }
                                break;
                            }
                        }

                        if (AL.GetError() != ALError.NoError)
                        {
                            StateChange(OggPlayerStatus.Error, OggPlayerStateChanger.Error);
                            lock (OALLocker) { AL.SourceStop(m_Source); }
                            Running = false;
                            break;
                        }
                        --ProcessedBuffers;
                    }

                    if (UnderRun) { lock (OALLocker) { AL.SourcePlay(m_Source); } }
                }
                else if (m_PlayerState == OggPlayerStatus.Paused) { }
                else { Running = false; }
                Thread.Sleep(10);
            }
        }