Exemple #1
0
        public void Play(OgvComponent video)
        {
            checkDisposed();

            // We need to assign this regardless of what happens next.
            Video = video;

            // FIXME: This is a part of the Duration hack!
            Video.Duration = TimeSpan.MaxValue;

            // Check the player state before attempting anything.
            if (State != MediaState.Stopped)
            {
                return;
            }

            // In rare cases, the thread might still be going. Wait until it's done.
            if (audioDecoderThread != null && audioDecoderThread.IsAlive)
            {
                Stop();
            }

            // Create new Thread instances in case we use this player multiple times.
            audioDecoderThread = new Thread(new ThreadStart(this.DecodeAudio));

            // Update the player state now, for the thread we're about to make.
            State = MediaState.Playing;

            // Start the video if it hasn't been yet.
            if (Video.IsDisposed)
            {
                video.Initialize();
            }

            // Grab the first bit of audio. We're trying to start the decoding ASAP.
            if (TheoraPlay.THEORAPLAY_hasAudioStream(Video.TheoraDecoder) != 0)
            {
                audioDecoderThread.Start();
            }
            else
            {
                audioStarted = true; // Welp.
            }

            // Grab the first bit of video, set up the texture.
            if (TheoraPlay.THEORAPLAY_hasVideoStream(Video.TheoraDecoder) != 0)
            {
                currentVideo  = TheoraPlay.getVideoFrame(Video.VideoStream);
                previousFrame = Video.VideoStream;
                do
                {
                    // The decoder miiight not be ready yet.
                    Video.VideoStream = TheoraPlay.THEORAPLAY_getVideo(Video.TheoraDecoder);
                } while (Video.VideoStream == IntPtr.Zero);
                nextVideo = TheoraPlay.getVideoFrame(Video.VideoStream);

                Texture overlap = videoTexture;
                videoTexture = new Texture(
//                    Game.Instance.GraphicsDevice,
//                    (int)currentVideo.width,
//                    (int)currentVideo.height,
//                    false,
//                    SurfaceFormat.Color
                    );
                overlap.Dispose();
#if VIDEOPLAYER_OPENGL
                GL_setupTargets(
                    (int)currentVideo.width,
                    (int)currentVideo.height
                    );
#endif
            }

            // Initialize the thread!
            Log.Editor.Write("Starting Theora player...");
            while (!audioStarted)
            {
                ;
            }
            timer.Start();
            if (audioSourceIndex != -1)
            {
                AL.SourcePlay(audioSourceIndex);
            }
            Log.Editor.Write(" Done starting Theora player!");
        }
        public void Play(OgvComponent video)
        {
            checkDisposed();

            // We need to assign this regardless of what happens next.
            Video = video;

            // FIXME: This is a part of the Duration hack!
            Video.Duration = TimeSpan.MaxValue;

            // Check the player state before attempting anything.
            if (State != MediaState.Stopped)
            {
                return;
            }

            // In rare cases, the thread might still be going. Wait until it's done.
            if (audioDecoderThread != null && audioDecoderThread.IsAlive)
            {
                Stop();
            }

            // Create new Thread instances in case we use this player multiple times.
            audioDecoderThread = new Thread(new ThreadStart(this.DecodeAudio));

            // Update the player state now, for the thread we're about to make.
            State = MediaState.Playing;

            // Start the video if it hasn't been yet.
            if (Video.IsDisposed)
            {
                video.Initialize();
            }

            // Grab the first bit of audio. We're trying to start the decoding ASAP.
            if (TheoraPlay.THEORAPLAY_hasAudioStream(Video.TheoraDecoder) != 0)
            {
                audioDecoderThread.Start();
            }
            else
            {
                audioStarted = true; // Welp.
            }

            // Grab the first bit of video, set up the texture.
            if (TheoraPlay.THEORAPLAY_hasVideoStream(Video.TheoraDecoder) != 0)
            {
                currentVideo = TheoraPlay.getVideoFrame(Video.VideoStream);
                previousFrame = Video.VideoStream;
                do
                {
                    // The decoder miiight not be ready yet.
                    Video.VideoStream = TheoraPlay.THEORAPLAY_getVideo(Video.TheoraDecoder);
                } while (Video.VideoStream == IntPtr.Zero);
                nextVideo = TheoraPlay.getVideoFrame(Video.VideoStream);

                Texture overlap = videoTexture;
                videoTexture = new Texture(
//                    Game.Instance.GraphicsDevice,
//                    (int)currentVideo.width,
//                    (int)currentVideo.height,
//                    false,
//                    SurfaceFormat.Color
                );
                overlap.Dispose();
#if VIDEOPLAYER_OPENGL
                GL_setupTargets(
                    (int)currentVideo.width,
                    (int)currentVideo.height
                );
#endif
            }

            // Initialize the thread!
            Log.Editor.Write("Starting Theora player...");
            while (!audioStarted) ;
            timer.Start();
            if (audioSourceIndex != -1)
            {
                AL.SourcePlay(audioSourceIndex);
            }
            Log.Editor.Write(" Done starting Theora player!");
        }