/// <summary> /// Plays the specified options. /// </summary> /// <param name="options">The options.</param> /// <returns>Task.</returns> /// <exception cref="ArgumentNullException"> /// options /// or /// options /// </exception> /// <exception cref="InvalidOperationException">There are no available players.</exception> public async Task Play(PlayOptions options) { if (options == null) { throw new ArgumentNullException("options"); } if (options.Items == null || options.Items.Count(i => i.LocationType != LocationType.Offline) == 0) { throw new ArgumentException("At least one item must be supplied."); } PlayerConfiguration config; var player = GetPlayer(options.Items, options.EnableCustomPlayers, out config); if (player == null) { throw new InvalidOperationException("There are no available players."); } StopAllPlayback(); await Task.Run(() => Play(player, options, config)); }
/// <summary> /// Gets the command arguments. /// </summary> /// <param name="items">The items.</param> /// <param name="options">The options.</param> /// <param name="isoMount">The iso mount.</param> /// <returns>System.String.</returns> protected virtual string GetCommandArguments(IEnumerable<BaseItemDto> items, PlayOptions options, IIsoMount isoMount) { return GetCommandArguments(items, options.Configuration.Args, isoMount); }
/// <summary> /// Gets the process start info. /// </summary> /// <param name="items">The items.</param> /// <param name="options">The options.</param> /// <param name="isoMount">The iso mount.</param> /// <returns>ProcessStartInfo.</returns> protected virtual ProcessStartInfo GetProcessStartInfo(IEnumerable<BaseItemDto> items, PlayOptions options, IIsoMount isoMount) { return new ProcessStartInfo { FileName = options.Configuration.Command, Arguments = GetCommandArguments(items, options, isoMount) }; }
/// <summary> /// Plays the specified options. /// </summary> /// <param name="options">The options.</param> /// <returns>Task.</returns> public async Task Play(PlayOptions options) { _currentIsoMount = options.Items.Count == 1 && options.Configuration.IsoMethod == IsoConfiguration.Mount ? await GetIsoMount(options.Items[0], CancellationToken.None) : null; CurrentPlaylistIndex = 0; CurrentPlayOptions = options; _playlist = options.Items.ToList(); var process = new Process { EnableRaisingEvents = true, StartInfo = GetProcessStartInfo(options.Items, options, _currentIsoMount) }; Logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); try { process.Start(); } catch (Exception ex) { Logger.ErrorException("Error starting player", ex); _playlist.Clear(); throw; } if (options.Configuration.CloseOnStopButton && !CanCloseAutomaticallyOnStopButton) { _userInput.GlobalKeyDown += KeyboardListener_KeyDown; } process.Exited += CurrentProcess_Exited; _currentProcess = process; OnPlayerLaunched(); }
/// <summary> /// Enables the madvr. /// </summary> /// <param name="options">The options.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> private bool EnableReclock(PlayOptions options) { var video = options.Items.First(); if (!video.IsVideo) { return false; } if (!_config.Configuration.InternalPlayerConfiguration.EnableReclock) { return false; } if (!options.GoFullScreen) { return false; } return true; }
public async Task Play(PlayOptions options) { CurrentPlaylistIndex = 0; CurrentPlayOptions = options; _playlist = options.Items.ToList(); try { await InvokeOnPlayerThreadAsync(() => { _mediaPlayer = new DirectShowPlayer(_logger, _windowManager, this, _presentation.MainApplicationWindowHandle, _sessionManager, _config/*, _inputManager*/); //HideCursor(); }); await PlayTrack(0, options.StartPositionTicks); } catch (Exception ex) { _logger.ErrorException("Error beginning playback", ex); DisposePlayer(); throw; } }
/// <summary> /// Plays the specified player. /// </summary> /// <param name="player">The player.</param> /// <param name="options">The options.</param> /// <param name="configuration">The configuration.</param> /// <returns>Task.</returns> private async Task Play(IMediaPlayer player, PlayOptions options, PlayerConfiguration configuration) { if (options.Items[0].IsPlaceHolder ?? false) { // play a phyical disk in the cdrom drive // Will be re-entrant call, so has to be made befpre the interlocked.CompareExchange below await PlayExternalDisk(true); return; } if (Interlocked.CompareExchange(ref _isStarting, 1, 0) == 0) // prevent race conditions, thread safe check we are not already starting to play an item { try { if (options.Shuffle) { options.Items = options.Items.OrderBy(i => Guid.NewGuid()).ToList(); } var firstItem = options.Items[0]; if (options.StartPositionTicks == 0 && player.SupportsMultiFilePlayback && firstItem.IsVideo && firstItem.LocationType == LocationType.FileSystem && options.GoFullScreen) { try { var intros = await _apiClient.GetIntrosAsync(firstItem.Id, _apiClient.CurrentUserId); options.Items.InsertRange(0, intros.Items); } catch (Exception ex) { _logger.ErrorException("Error retrieving intros", ex); } } options.Configuration = configuration; var playTask = player.Play(options); if (player is IInternalMediaPlayer && player is IVideoPlayer && firstItem.IsVideo) { if (options.GoFullScreen) { await _nav.Navigate(Go.To.FullScreenPlayback()); } } await playTask; OnPlaybackStarted(player, options); } finally { Interlocked.Exchange(ref _isStarting, 0); } } }
/// <summary> /// Called when [playback started]. /// </summary> /// <param name="player">The player.</param> /// <param name="options">The options.</param> private async void OnPlaybackStarted(IMediaPlayer player, PlayOptions options) { await _playbackStart.Publish(new PlaybackStartEventArgs { Options = options, Player = player }); await new PlaybackProgressReporter(_apiClient, player, _logger, this).Start().ConfigureAwait(false); }