static MediaPlayer() { MediaManager.Startup(true); using (var factory = new MediaEngineClassFactory()) { var mediaEngine = new MediaEngine(factory, null, MediaEngineCreateflags.Audioonly); _mediaEngineEx = mediaEngine.QueryInterface<MediaEngineEx>(); } _mediaEngineEx.PlaybackEvent += MediaEngineExOnPlaybackEvent; }
static void Main(string[] args) { // Select a File to play var openFileDialog = new OpenFileDialog { Title = "Select a music file", Filter = "Music Files(*.WMA;*.MP3;*.WAV)|*.WMA;*.MP3;*.WAV" }; var result = openFileDialog.ShowDialog(); if (result == DialogResult.Cancel) { return; } // Initialize MediaFoundation MediaManager.Startup(); // Creates the MediaEngineClassFactory var mediaEngineFactory = new MediaEngineClassFactory(); // Creates MediaEngine for AudioOnly var mediaEngine = new MediaEngine(mediaEngineFactory, null, MediaEngineCreateFlags.AudioOnly); // Register our PlayBackEvent mediaEngine.PlaybackEvent += OnPlaybackCallback; // Query for MediaEngineEx interface mediaEngineEx = mediaEngine.QueryInterface<MediaEngineEx>(); // Opens the file var fileStream = openFileDialog.OpenFile(); // Create a ByteStream object from it var stream = new ByteStream(fileStream); // Creates an URL to the file var url = new Uri(openFileDialog.FileName, UriKind.RelativeOrAbsolute); // Set the source stream mediaEngineEx.SetSourceFromByteStream(stream, url.AbsoluteUri); // Wait for MediaEngine to be ready if (!eventReadyToPlay.WaitOne(1000)) { Console.WriteLine("Unexpected error: Unable to play this file"); } // Play the music mediaEngineEx.Play(); // Wait until music is stopped. while (!isMusicStopped) { Thread.Sleep(10); } }
private static void PlatformInitialize() { MediaManager.Startup(true); using (var factory = new MediaEngineClassFactory()) using (var attributes = new MediaEngineAttributes { AudioCategory = AudioStreamCategory.GameMedia }) { var creationFlags = MediaEngineCreateFlags.AudioOnly; var mediaEngine = new MediaEngine(factory, attributes, creationFlags, MediaEngineExOnPlaybackEvent); _mediaEngineEx = mediaEngine.QueryInterface<MediaEngineEx>(); } _dispatcher = CoreWindow.GetForCurrentThread().Dispatcher; }
internal override void InitImpl() { // Setup Media Engine attributes using (var attributes = new MediaEngineAttributes { AudioEndpointRole = AudioEndpointRole.Console, AudioCategory = AudioStreamCategory.GameEffects }) { var creationFlags = MediaEngineCreateFlags.None; #if !SILICONSTUDIO_PLATFORM_WINDOWS_PHONE // MSDN: On the phone, the Media Engine only supports frame-server mode. Attempting to initialize the interface in either rendering mode or audio mode will fail. creationFlags |= MediaEngineCreateFlags.AudioOnly; #endif using (var factory = new MediaEngineClassFactory()) mediaEngine = new MediaEngine(factory, attributes, creationFlags, OnMediaEngineEvent); mediaEngineEx = mediaEngine.QueryInterface<MediaEngineEx>(); } }
private void PlatformInitialize() { MediaManager.Startup(); _devManager = new DXGIDeviceManager(); _devManager.ResetDevice(Game.Instance.GraphicsDevice._d3dDevice); using (var factory = new MediaEngineClassFactory()) using (var attributes = new MediaEngineAttributes { VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm, DxgiManager = _devManager }) { _mediaEngine = new MediaEngine(factory, attributes, MediaEngineCreateFlags.None, OnMediaEngineEvent); } }
public virtual void Initialize(DeviceManager deviceManager) { lock (lockObject) { // Startup MediaManager MediaManager.Startup(); // Setup multithread on the Direct3D11 device var multithread = deviceManager.DeviceDirect3D.QueryInterface<SharpDX.Direct3D.DeviceMultithread>(); multithread.SetMultithreadProtected(true); // Create a DXGI Device Manager dxgiDeviceManager = new DXGIDeviceManager(); dxgiDeviceManager.ResetDevice(deviceManager.DeviceDirect3D); // Setup Media Engine attributes var attributes = new MediaEngineAttributes { DxgiManager = dxgiDeviceManager, VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm }; using (var factory = new MediaEngineClassFactory()) mediaEngine = new MediaEngine(factory, attributes, MediaEngineCreateFlags.WaitForStableState, OnMediaEngineEvent); mediaEngineEx = mediaEngine.QueryInterface<MediaEngineEx>(); } }
public MediaEngineNotifyImpl(MediaEngine mediaEngine) { MediaEngine = mediaEngine; }
protected override void OnNavigatedTo(NavigationEventArgs e) { //this.mediaEngine.Play(); //this.mediaEngine.Load(); // this.mediaEngine.GetNativeVideoSize(out width, out height); context = new SharpDXContext(); context.Render += context_Render; context.DeviceReset += context_DeviceReset; context.BindToControl(this.Surface); DeviceMultithread mt = context.D3DDevice.QueryInterface<DeviceMultithread>(); mt.SetMultithreadProtected(true); deviceManager = new DXGIDeviceManager(); deviceManager.ResetDevice(context.D3DDevice); MediaEngineAttributes attr = new MediaEngineAttributes(); attr.VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm; attr.DxgiManager = deviceManager; this.mediaFactory = new MediaEngineClassFactory(); this.mediaEngine = new MediaEngine(this.mediaFactory, attr, MediaEngineCreateFlags.None); // this.mediaEngineEx = this.mediaEngine.QueryInterface<MediaEngineEx>(); this.mediaEngine.PlaybackEvent += mediaEngine_PlaybackEvent; this.mediaEngine.Source = Package.Current.InstalledLocation.Path + "/Assets/keloid.mp4"; this.mediaEngine.Load(); ushort[] indices = new ushort[] { 0, 1, 2, 2, 3, 0, }; this.indexBuffer = SharpDX.Direct3D11.Buffer.Create<ushort>(this.context.D3DDevice, BindFlags.IndexBuffer, indices); float[] vertices = new float[] { // 3D coordinates UV Texture coordinates -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Front -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, // BACK 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Top -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f,-1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Bottom 1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f,-1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f,-1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Left -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, -1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Right 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, }; this.vertexBuffer = SharpDX.Direct3D11.Buffer.Create<float>(this.context.D3DDevice, BindFlags.VertexBuffer, vertices); this.bufferBinding = new VertexBufferBinding(this.vertexBuffer, sizeof(float) * 6, 0); var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path; // Loads vertex shader bytecode var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCubeTexture_VS.fxo"); this.vertexShader = new VertexShader(this.context.D3DDevice, vertexShaderByteCode); this.inputLayout = new InputLayout(this.context.D3DDevice, vertexShaderByteCode, new[] { new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 16, 0) }); this.pixelShader = new PixelShader(this.context.D3DDevice, NativeFile.ReadAllBytes(path + "\\MiniCubeTexture_PS.fxo")); this.constantBuffer = new SharpDX.Direct3D11.Buffer(this.context.D3DDevice, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); this.sampler = new SamplerState(this.context.D3DDevice, new SamplerStateDescription() { Filter = Filter.MinMagMipLinear, AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, BorderColor = Color.Black, ComparisonFunction = Comparison.Never, MaximumAnisotropy = 16, MipLodBias = 0, MinimumLod = -float.MaxValue, MaximumLod = float.MaxValue }); base.OnNavigatedTo(e); }
static void Main(string[] args) { // Select a File to play var openFileDialog = new OpenFileDialog { Title = "Select a file", Filter = "Media Files(*.WMV;*.MP4;*.AVI)|*.WMV;*.MP4;*.AVI" }; var result = openFileDialog.ShowDialog(); if (result == DialogResult.Cancel) { return; } // Initialize MediaFoundation MediaManager.Startup(); var renderForm = new SharpDX.Windows.RenderForm(); device = CreateDeviceForVideo(out dxgiManager); // Creates the MediaEngineClassFactory var mediaEngineFactory = new MediaEngineClassFactory(); //Assign our dxgi manager, and set format to bgra MediaEngineAttributes attr = new MediaEngineAttributes(); attr.VideoOutputFormat = (int)SharpDX.DXGI.Format.B8G8R8A8_UNorm; attr.DxgiManager = dxgiManager; // Creates MediaEngine for AudioOnly var mediaEngine = new MediaEngine(mediaEngineFactory, attr, MediaEngineCreateFlags.None); // Register our PlayBackEvent mediaEngine.PlaybackEvent += OnPlaybackCallback; // Query for MediaEngineEx interface mediaEngineEx = mediaEngine.QueryInterface<MediaEngineEx>(); // Opens the file var fileStream = openFileDialog.OpenFile(); // Create a ByteStream object from it var stream = new ByteStream(fileStream); // Creates an URL to the file var url = new Uri(openFileDialog.FileName, UriKind.RelativeOrAbsolute); // Set the source stream mediaEngineEx.SetSourceFromByteStream(stream, url.AbsoluteUri); // Wait for MediaEngine to be ready if (!eventReadyToPlay.WaitOne(1000)) { Console.WriteLine("Unexpected error: Unable to play this file"); } //Create our swapchain swapChain = CreateSwapChain(device, renderForm.Handle); //Get DXGI surface to be used by our media engine var texture = Texture2D.FromSwapChain<Texture2D>(swapChain, 0); var surface = texture.QueryInterface<SharpDX.DXGI.Surface>(); //Get our video size int w, h; mediaEngine.GetNativeVideoSize(out w, out h); // Play the music mediaEngineEx.Play(); long ts; RenderLoop.Run(renderForm, () => { //Transfer frame if a new one is available if (mediaEngine.OnVideoStreamTick(out ts)) { mediaEngine.TransferVideoFrame(surface, null, new SharpDX.Rectangle(0, 0, w, h), null); } swapChain.Present(1, SharpDX.DXGI.PresentFlags.None); }); mediaEngine.Shutdown(); swapChain.Dispose(); device.Dispose(); }