public void SetMediaItem(LibRetroMediaItem mediaItem) { if (_retro != null) { return; } _state = PlayerState.Active; IResourceLocator locator = mediaItem.GetResourceLocator(); string gamePath; if (!string.IsNullOrEmpty(mediaItem.ExtractedPath)) { gamePath = mediaItem.ExtractedPath; } else if (locator.TryCreateLocalFsAccessor(out _accessor)) { gamePath = _accessor.LocalFileSystemPath; } else { return; } string saveName = DosPathHelper.GetFileNameWithoutExtension(locator.NativeResourcePath.FileName); ServiceRegistration.Get <ILogger>().Debug("LibRetroPlayer: Creating LibRetroFrontend: Core Path '{0}', Game Path '{1}', Save Name '{2}'", mediaItem.LibRetroPath, gamePath, saveName); _corePath = mediaItem.LibRetroPath; _isCoreLoaded = ServiceRegistration.Get <ILibRetroCoreInstanceManager>().TrySetCoreLoading(_corePath); if (!_isCoreLoaded) { ShowLoadErrorDialog(); return; } _retro = new LibRetroFrontend(mediaItem.LibRetroPath, gamePath, saveName); _isLibretroInit = _retro.Init(); //if (_isLibretroInit) //{ // TimingInfo timingInfo = _retro.GetTimingInfo(); // if (timingInfo != null) // MediaItemAspect.SetAttribute(mediaItem.Aspects, VideoAspect.ATTR_FPS, (int)timingInfo.FPS); //} }
public void SetMediaItem(IResourceLocator locator, string mediaItemTitle) { // free previous opened resource FilterGraphTools.TryDispose(ref _resourceAccessor); FilterGraphTools.TryDispose(ref _rot); _state = PlayerState.Active; _isPaused = true; try { _resourceLocator = locator; _mediaItemTitle = mediaItemTitle; if (_resourceLocator.NativeResourcePath.IsNetworkResource) { _resourceAccessor = _resourceLocator.CreateAccessor() as INetworkResourceAccessor; if (_resourceAccessor == null) throw new IllegalCallException("The VideoPlayer can only play network resources of type INetworkResourceAccessor"); ServiceRegistration.Get<ILogger>().Debug("{0}: Initializing for network media item '{1}'", PlayerTitle, SourcePathOrUrl); } else { ILocalFsResourceAccessor lfsr; if (!_resourceLocator.TryCreateLocalFsAccessor(out lfsr)) throw new IllegalCallException("The VideoPlayer can only play local file system resources"); _resourceAccessor = lfsr; ServiceRegistration.Get<ILogger>().Debug("{0}: Initializing for media item '{1}'", PlayerTitle, SourcePathOrUrl); } // Create a DirectShow FilterGraph CreateGraphBuilder(); // Add it in ROT (Running Object Table) for debug purpose, it allows to view the Graph from outside (i.e. graphedit) _rot = new DsROTEntry(_graphBuilder); // Add a notification handler (see WndProc) _instancePtr = Marshal.AllocCoTaskMem(4); IMediaEventEx mee = _graphBuilder as IMediaEventEx; if (mee != null) mee.SetNotifyWindow(SkinContext.Form.Handle, WM_GRAPHNOTIFY, _instancePtr); // Create the Allocator / Presenter object AddPresenter(); ServiceRegistration.Get<ILogger>().Debug("{0}: Adding audio renderer", PlayerTitle); AddAudioRenderer(); ServiceRegistration.Get<ILogger>().Debug("{0}: Adding preferred codecs", PlayerTitle); AddPreferredCodecs(); ServiceRegistration.Get<ILogger>().Debug("{0}: Adding file source", PlayerTitle); AddFileSource(); ServiceRegistration.Get<ILogger>().Debug("{0}: Run graph", PlayerTitle); //This needs to be done here before we check if the evr pins are connected //since this method gives players the chance to render the last bits of the graph OnBeforeGraphRunning(); // Now run the graph, i.e. the DVD player needs a running graph before getting informations from dvd filter. IMediaControl mc = (IMediaControl) _graphBuilder; int hr = mc.Run(); DsError.ThrowExceptionForHR(hr); _initialized = true; OnGraphRunning(); } catch (Exception) { Shutdown(); throw; } }
public void SetMediaItem(IResourceLocator locator, string mediaItemTitle) { // free previous opened resource FilterGraphTools.TryDispose(ref _resourceAccessor); FilterGraphTools.TryDispose(ref _rot); _state = PlayerState.Active; _isPaused = true; try { _resourceLocator = locator; _mediaItemTitle = mediaItemTitle; if (_resourceLocator.NativeResourcePath.IsNetworkResource) { _resourceAccessor = _resourceLocator.CreateAccessor() as INetworkResourceAccessor; if (_resourceAccessor == null) { throw new IllegalCallException("The VideoPlayer can only play network resources of type INetworkResourceAccessor"); } ServiceRegistration.Get <ILogger>().Debug("{0}: Initializing for network media item '{1}'", PlayerTitle, SourcePathOrUrl); } else { ILocalFsResourceAccessor lfsr; if (!_resourceLocator.TryCreateLocalFsAccessor(out lfsr)) { throw new IllegalCallException("The VideoPlayer can only play local file system resources"); } _resourceAccessor = lfsr; ServiceRegistration.Get <ILogger>().Debug("{0}: Initializing for media item '{1}'", PlayerTitle, SourcePathOrUrl); } // Create a DirectShow FilterGraph CreateGraphBuilder(); // Add it in ROT (Running Object Table) for debug purpose, it allows to view the Graph from outside (i.e. graphedit) _rot = new DsROTEntry(_graphBuilder); // Add a notification handler (see WndProc) _instancePtr = Marshal.AllocCoTaskMem(4); IMediaEventEx mee = _graphBuilder as IMediaEventEx; if (mee != null) { mee.SetNotifyWindow(SkinContext.Form.Handle, WM_GRAPHNOTIFY, _instancePtr); } // Create the Allocator / Presenter object AddPresenter(); ServiceRegistration.Get <ILogger>().Debug("{0}: Adding audio renderer", PlayerTitle); AddAudioRenderer(); ServiceRegistration.Get <ILogger>().Debug("{0}: Adding preferred codecs", PlayerTitle); AddPreferredCodecs(); ServiceRegistration.Get <ILogger>().Debug("{0}: Adding file source", PlayerTitle); AddFileSource(); ServiceRegistration.Get <ILogger>().Debug("{0}: Run graph", PlayerTitle); //This needs to be done here before we check if the evr pins are connected //since this method gives players the chance to render the last bits of the graph OnBeforeGraphRunning(); // Now run the graph, i.e. the DVD player needs a running graph before getting informations from dvd filter. IMediaControl mc = (IMediaControl)_graphBuilder; int hr = mc.Run(); DsError.ThrowExceptionForHR(hr); _initialized = true; OnGraphRunning(); } catch (Exception) { Shutdown(); throw; } }