Esempio n. 1
0
        private void PlatformInitialize()
        {
            // The GUID is specified in a GuidAttribute attached to the class
            AudioStreamVolumeGuid = Guid.Parse(((GuidAttribute)typeof(AudioStreamVolume).GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value);

            MediaManagerState.CheckStartup();
            MediaFactory.CreateMediaSession(null, out _session);
        }
Esempio n. 2
0
        private static void PlatformInitialize()
        {
            // The GUID is specified in a GuidAttribute attached to the class
            AudioStreamVolumeGuid = Guid.Parse(((GuidAttribute)typeof(AudioStreamVolume).GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value);

            MediaManagerState.CheckStartup();
            MediaFactory.CreateMediaSession(null, out _session);

            _callback = new Callback();
            _session.BeginGetEvent(_callback, null);

            _clock = _session.Clock.QueryInterface <PresentationClock>();
        }
Esempio n. 3
0
        static MediaPlayer()
        {
#if WINDOWS_MEDIA_ENGINE
            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;
#elif WINDOWS_MEDIA_SESSION
            MediaManagerState.CheckStartup();
            MediaFactory.CreateMediaSession(null, out _session);
#elif WINDOWS_PHONE
            PhoneApplicationService.Current.Activated += (sender, e) =>
            {
                if (_mediaElement != null)
                {
                    if (_mediaElement.Source == null && source != null)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() => _mediaElement.Source = source);
                    }

                    // Ensure only one subscription
                    _mediaElement.MediaOpened -= MediaElement_MediaOpened;
                    _mediaElement.MediaOpened += MediaElement_MediaOpened;
                }
            };

            PhoneApplicationService.Current.Deactivated += (sender, e) =>
            {
                if (_mediaElement != null)
                {
                    source      = _mediaElement.Source;
                    elapsedTime = _mediaElement.Position;
                }
            };
#endif
        }
Esempio n. 4
0
        private void PlatformInitialize()
        {
            if (Topology != null)
            {
                return;
            }

            MediaManagerState.CheckStartup();

            MediaFactory.CreateTopology(out _topology);

            SharpDX.MediaFoundation.MediaSource mediaSource;
            {
                SourceResolver resolver = new SourceResolver();

                ObjectType otype;
                ComObject  source = resolver.CreateObjectFromURL(FileName, SourceResolverFlags.MediaSource, null, out otype);
                mediaSource = source.QueryInterface <SharpDX.MediaFoundation.MediaSource>();
                resolver.Dispose();
                source.Dispose();
            }

            PresentationDescriptor presDesc;

            mediaSource.CreatePresentationDescriptor(out presDesc);

            for (var i = 0; i < presDesc.StreamDescriptorCount; i++)
            {
                SharpDX.Mathematics.Interop.RawBool selected;
                StreamDescriptor desc;
                presDesc.GetStreamDescriptorByIndex(i, out selected, out desc);

                if (selected)
                {
                    TopologyNode sourceNode;
                    MediaFactory.CreateTopologyNode(TopologyType.SourceStreamNode, out sourceNode);

                    sourceNode.Set(TopologyNodeAttributeKeys.Source, mediaSource);
                    sourceNode.Set(TopologyNodeAttributeKeys.PresentationDescriptor, presDesc);
                    sourceNode.Set(TopologyNodeAttributeKeys.StreamDescriptor, desc);

                    TopologyNode outputNode;
                    MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out outputNode);

                    var majorType = desc.MediaTypeHandler.MajorType;
                    if (majorType == MediaTypeGuids.Video)
                    {
                        Activate activate;

                        SampleGrabber = new VideoSampleGrabber();

                        _mediaType = new MediaType();

                        _mediaType.Set(MediaTypeAttributeKeys.MajorType, MediaTypeGuids.Video);

                        // Specify that we want the data to come in as RGB32.
                        _mediaType.Set(MediaTypeAttributeKeys.Subtype, new Guid("00000016-0000-0010-8000-00AA00389B71"));

                        MediaFactory.CreateSampleGrabberSinkActivate(_mediaType, SampleGrabber, out activate);
                        outputNode.Object = activate;
                    }

                    if (majorType == MediaTypeGuids.Audio)
                    {
                        Activate activate;
                        MediaFactory.CreateAudioRendererActivate(out activate);

                        outputNode.Object = activate;
                    }

                    _topology.AddNode(sourceNode);
                    _topology.AddNode(outputNode);
                    sourceNode.ConnectOutput(0, outputNode, 0);

                    sourceNode.Dispose();
                    outputNode.Dispose();
                }

                desc.Dispose();
            }

            presDesc.Dispose();
            mediaSource.Dispose();
        }
Esempio n. 5
0
 private void PlatformInitialize()
 {
     MediaManagerState.CheckStartup();
     MediaFactory.CreateMediaSession(null, out _session);
 }
Esempio n. 6
0
        internal Topology GetTopology()
        {
            if (_topology == null)
            {
                MediaManagerState.CheckStartup();

                MediaFactory.CreateTopology(out _topology);

                SharpDX.MediaFoundation.MediaSource mediaSource;
                {
                    SourceResolver resolver;
                    MediaFactory.CreateSourceResolver(out resolver);

                    ObjectType otype;
                    ComObject  source;
                    resolver.CreateObjectFromURL(FilePath, (int)SourceResolverFlags.MediaSource, null, out otype,
                                                 out source);
                    mediaSource = source.QueryInterface <SharpDX.MediaFoundation.MediaSource>();
                    resolver.Dispose();
                    source.Dispose();
                }

                PresentationDescriptor presDesc;
                mediaSource.CreatePresentationDescriptor(out presDesc);

                for (var i = 0; i < presDesc.StreamDescriptorCount; i++)
                {
                    Bool             selected;
                    StreamDescriptor desc;
                    presDesc.GetStreamDescriptorByIndex(i, out selected, out desc);

                    if (selected)
                    {
                        TopologyNode sourceNode;
                        MediaFactory.CreateTopologyNode(TopologyType.SourceStreamNode, out sourceNode);

                        sourceNode.Set(TopologyNodeAttributeKeys.Source, mediaSource);
                        sourceNode.Set(TopologyNodeAttributeKeys.PresentationDescriptor, presDesc);
                        sourceNode.Set(TopologyNodeAttributeKeys.StreamDescriptor, desc);

                        TopologyNode outputNode;
                        MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out outputNode);

                        var majorType = desc.MediaTypeHandler.MajorType;
                        if (majorType != MediaTypeGuids.Audio)
                        {
                            throw new NotSupportedException("The song contains video data!");
                        }

                        Activate activate;
                        MediaFactory.CreateAudioRendererActivate(out activate);
                        outputNode.Object = activate;

                        _topology.AddNode(sourceNode);
                        _topology.AddNode(outputNode);
                        sourceNode.ConnectOutput(0, outputNode, 0);

                        sourceNode.Dispose();
                        outputNode.Dispose();
                    }

                    desc.Dispose();
                }

                presDesc.Dispose();
                mediaSource.Dispose();
            }

            return(_topology);
        }
Esempio n. 7
0
        private void PlatformInitialize(string fileName)
        {
            if (_topology != null)
            {
                return;
            }

            MediaManagerState.CheckStartup();

            MediaFactory.CreateTopology(out _topology);

            SharpDX.MediaFoundation.MediaSource mediaSource;
            {
                SourceResolver resolver = new SourceResolver();

                ComObject source = resolver.CreateObjectFromURL(FilePath, SourceResolverFlags.MediaSource);
                mediaSource = source.QueryInterface <SharpDX.MediaFoundation.MediaSource>();
                resolver.Dispose();
                source.Dispose();
            }

            PresentationDescriptor presDesc;

            mediaSource.CreatePresentationDescriptor(out presDesc);

            for (var i = 0; i < presDesc.StreamDescriptorCount; i++)
            {
                SharpDX.Mathematics.Interop.RawBool selected;
                StreamDescriptor desc;
                presDesc.GetStreamDescriptorByIndex(i, out selected, out desc);

                if (selected)
                {
                    TopologyNode sourceNode;
                    MediaFactory.CreateTopologyNode(TopologyType.SourceStreamNode, out sourceNode);

                    sourceNode.Set(TopologyNodeAttributeKeys.Source, mediaSource);
                    sourceNode.Set(TopologyNodeAttributeKeys.PresentationDescriptor, presDesc);
                    sourceNode.Set(TopologyNodeAttributeKeys.StreamDescriptor, desc);

                    TopologyNode outputNode;
                    MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out outputNode);

                    var typeHandler = desc.MediaTypeHandler;
                    var majorType   = typeHandler.MajorType;
                    if (majorType != MediaTypeGuids.Audio)
                    {
                        throw new NotSupportedException("The song contains video data!");
                    }

                    Activate activate;
                    MediaFactory.CreateAudioRendererActivate(out activate);
                    outputNode.Object = activate;

                    _topology.AddNode(sourceNode);
                    _topology.AddNode(outputNode);
                    sourceNode.ConnectOutput(0, outputNode, 0);

                    sourceNode.Dispose();
                    outputNode.Dispose();
                    typeHandler.Dispose();
                    activate.Dispose();
                }

                desc.Dispose();
            }

            presDesc.Dispose();
            mediaSource.Dispose();
        }