Exemplo n.º 1
0
        public ApplicationConfiguration()
        {
            // default sever and theme settings
            ServerHostName = "127.0.0.1";
            ServerApiPort = 8096;
            ActiveThemeGuid = new Guid("C501C937-3BC9-471A-A538-20FAA9B7CE51");
            EnableHighQualityImageScaling = true;

            AutoLoginConfiguration = new AutoLoginConfiguration();
            WakeOnLanConfiguration = new WolConfiguration();
            InternalPlayerConfiguration = new InternalPlayerConfiguration();
            MediaPlayers = new PlayerConfiguration[0];
        }
Exemplo n.º 2
0
        /// <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);
                }
            }
        }
Exemplo n.º 3
0
        private bool IsConfiguredForFileExtension(PlayerConfiguration configuration, string path)
        {
            var extensions = configuration.FileExtensions.Select(i => i.TrimStart('.'));

            return extensions.Contains(Path.GetExtension(path).TrimStart('.'), StringComparer.OrdinalIgnoreCase);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Determines whether [is configured to play] [the specified configuration].
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="item">The item.</param>
        /// <returns><c>true</c> if [is configured to play] [the specified configuration]; otherwise, <c>false</c>.</returns>
        private bool IsConfiguredToPlay(PlayerConfiguration configuration, BaseItemDto item)
        {
            // Make this configurable if/when needed
            if (item.LocationType != LocationType.FileSystem)
            {
                return false;
            }

            // If it's configured for specific item types
            if (!string.Equals(configuration.MediaType, item.MediaType, StringComparison.OrdinalIgnoreCase))
            {
                return false;
            }

            if (string.Equals(configuration.MediaType, MediaType.Video))
            {
                if (!item.VideoType.HasValue)
                {
                    return false;
                }

                if (item.VideoType.Value == VideoType.VideoFile)
                {
                    // If it's configured for specific file extensions
                    if (!IsConfiguredForFileExtension(configuration, item.Path))
                    {
                        return false;
                    }
                }

                if (item.VideoType.Value == VideoType.BluRay && !configuration.PlayBluray)
                {
                    return false;
                }
                if (item.VideoType.Value == VideoType.Dvd && !configuration.PlayDvd)
                {
                    return false;
                }

                if (!configuration.Play3DVideo && item.Video3DFormat.HasValue)
                {
                    return false;
                }

                if (item.VideoType.Value == VideoType.Iso & configuration.IsoMethod == IsoConfiguration.None)
                {
                    return false;
                }
            }

            else if (string.Equals(configuration.MediaType, MediaType.Book))
            {
                // If it's configured for specific file extensions
                if (!IsConfiguredForFileExtension(configuration, item.Path))
                {
                    return false;
                }
            }

            else if (string.Equals(configuration.MediaType, MediaType.Audio))
            {
                // If it's configured for specific file extensions
                if (!IsConfiguredForFileExtension(configuration, item.Path))
                {
                    return false;
                }
            }

            else if (string.Equals(configuration.MediaType, MediaType.Game))
            {
                // If it's configured for specific file extensions
                if (!string.Equals(item.GameSystem, configuration.GameSystem, StringComparison.OrdinalIgnoreCase))
                {
                    return false;
                }
            }

            return true;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Determines whether [is configured to play] [the specified configuration].
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="items">The items.</param>
 /// <returns><c>true</c> if [is configured to play] [the specified configuration]; otherwise, <c>false</c>.</returns>
 private bool IsConfiguredToPlay(PlayerConfiguration configuration, IEnumerable<BaseItemDto> items)
 {
     return items.All(i => IsConfiguredToPlay(configuration, i));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the player.
        /// </summary>
        /// <param name="items">The items.</param>
        /// <param name="enableCustomPlayers">if set to <c>true</c> [enable custom players].</param>
        /// <param name="configuration">The configuration.</param>
        /// <returns>IMediaPlayer.</returns>
        private IMediaPlayer GetPlayer(IEnumerable<BaseItemDto> items, bool enableCustomPlayers, out PlayerConfiguration configuration)
        {
            if (enableCustomPlayers)
            {
                var configuredPlayer = _configurationManager.Configuration.MediaPlayers
                    .FirstOrDefault(p => IsConfiguredToPlay(p, items));

                if (configuredPlayer != null)
                {
                    var player = MediaPlayers.FirstOrDefault(i => string.Equals(i.Name, configuredPlayer.PlayerName, StringComparison.OrdinalIgnoreCase));

                    if (player != null)
                    {
                        configuration = configuredPlayer;
                        return player;
                    }
                }
            }

            configuration = null;

            // If there's no explicit configuration just find the first matching player who says they can play it
            return MediaPlayers.FirstOrDefault(p => items.All(p.CanPlayByDefault));
        }