Beispiel #1
0
        private void OnEngineEvent(MediaEngineEvent mediaevent, long param1, int param2)
        {
            switch (mediaevent)
            {
            case MediaEngineEvent.DurationChange:
                SetDuration(engine.Duration);
                break;

            case MediaEngineEvent.LoadStart:
                SetCurrentState(StreamPlayerState.LoadingSource);
                break;

            case MediaEngineEvent.LoadedMetadata:
                int x, y;
                engine.GetNativeVideoSize(out x, out y);
                using (var texture = new Texture2D(Device, new Texture2DDescription
                {
                    Format = Format.B8G8R8A8_UNorm,
                    Width = x,
                    Height = y,
                    ArraySize = 1,
                    MipLevels = 1,
                    SampleDescription = new SampleDescription
                    {
                        Count = 1
                    },
                    BindFlags = BindFlags.RenderTarget,
                }))
                {
                    TargetSurface?.Dispose();
                    TargetSurface = texture.QueryInterface <Surface>();
                    OnNewSurface(x, y);
                    SetCurrentTime(TimeSpan.Zero);
                }
                break;

            case MediaEngineEvent.CanPlay:
                SetCurrentState(StreamPlayerState.CanPlay);
                break;

            case MediaEngineEvent.CanPlayThrough:
                SetCurrentState(StreamPlayerState.CanPlayFully);
                break;

            case MediaEngineEvent.Error:
                // We don't want to throw on this thread, so instead break the debugger
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    var exception = System.Runtime.InteropServices.Marshal.GetExceptionForHR(param2);
                    System.Diagnostics.Debugger.Break();
                }
                break;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Plays the audio/video.
        /// </summary>
        public void Play()
        {
            if (mediaEngineEx != null)
            {
                if (mediaEngineEx.HasVideo() && isVideoStopped)
                {
                    isVideoStopped = false;
                }

                if (IsEndOfStream)
                {
                    PlaybackPosition = 0;
                    IsPlaying        = true;
                }
                else
                {
                    if (textureView == null)
                    {
                        int width  = 0;
                        int height = 0;

                        mediaEngineEx.GetNativeVideoSize(out width, out height);

                        OutputVideoTexture = new SharpDX.Direct3D11.Texture2D(
                            d3dDevice,
                            new SharpDX.Direct3D11.Texture2DDescription()
                        {
                            ArraySize         = 1,
                            Width             = width,
                            Height            = height,
                            Usage             = SharpDX.Direct3D11.ResourceUsage.Default,
                            Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                            CpuAccessFlags    = SharpDX.Direct3D11.CpuAccessFlags.None,
                            BindFlags         = SharpDX.Direct3D11.BindFlags.RenderTarget | SharpDX.Direct3D11.BindFlags.ShaderResource,
                            OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.None,
                            SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                            MipLevels         = 1,
                        });

                        textureView = new ShaderResourceView(d3dDevice, OutputVideoTexture);
                    }

                    mediaEngineEx.Play();
                }

                IsEndOfStream = false;
            }
        }