Exemplo n.º 1
0
        internal async void OnPlaybackStopped(PlayableItem media, long?positionTicks, TrackCompletionReason reason, int?newTrackIndex)
        {
            DisposeMount(media);

            if (reason == TrackCompletionReason.Ended || reason == TrackCompletionReason.ChangeTrack)
            {
                var nextIndex = newTrackIndex ?? (CurrentPlaylistIndex + 1);

                if (nextIndex < CurrentPlayOptions.Items.Count)
                {
                    await PlayTrack(nextIndex, null);

                    return;
                }
            }

            DisposePlayer();

            StopTranscoding(media);

            var args = new PlaybackStopEventArgs
            {
                Player              = this,
                Playlist            = _playlist,
                EndingMedia         = media.OriginalItem,
                EndingPositionTicks = positionTicks
            };

            EventHelper.FireEventIfNotNull(PlaybackCompleted, this, args, _logger);

            _playbackManager.ReportPlaybackCompleted(args);
        }
Exemplo n.º 2
0
 private async void StopTranscoding(PlayableItem media)
 {
     // If streaming video, stop the transcoder
     if (media.IsVideo && media.PlayablePath.IndexOf("://", StringComparison.OrdinalIgnoreCase) != -1)
     {
         try
         {
             await _apiClient.StopTranscodingProcesses(_apiClient.DeviceId);
         }
         catch
         {
         }
     }
 }
Exemplo n.º 3
0
 private void DisposeMount(PlayableItem media)
 {
     if (media.IsoMount != null)
     {
         try
         {
             media.IsoMount.Dispose();
             media.IsoMount = null;
         }
         catch (Exception ex)
         {
             _logger.ErrorException("Error unmounting iso {0}", ex, media.IsoMount.MountedPath);
         }
     }
 }
Exemplo n.º 4
0
        private async void StopTranscoding(PlayableItem media)
        {
            // If streaming video, stop the transcoder
            if (media.IsVideo && media.PlayablePath.IndexOf("://", StringComparison.OrdinalIgnoreCase) != -1)
            {
                var apiClient = _connectionManager.GetApiClient(media.OriginalItem);

                try
                {
                    await apiClient.StopTranscodingProcesses(apiClient.DeviceId);
                }
                catch
                {
                }
            }
        }
Exemplo n.º 5
0
        public void Play(PlayableItem item, bool enableReclock, bool enableMadvr, bool enableXySubFilter)
        {
            _logger.Info("Playing {0}. Reclock: {1}, Madvr: {2}, xySubFilter: {3}", item.OriginalItem.Name, enableReclock, enableMadvr, enableXySubFilter);

            _item = item;

            var isDvd = (item.OriginalItem.VideoType ?? VideoType.VideoFile) == VideoType.Dvd || (item.OriginalItem.IsoType ?? IsoType.BluRay) == IsoType.Dvd && item.PlayablePath.IndexOf("http://", StringComparison.OrdinalIgnoreCase) == -1;

            Initialize(item.PlayablePath, enableReclock, enableMadvr, enableXySubFilter, isDvd);

            var hr = _mediaControl.Run();

            DsError.ThrowExceptionForHR(hr);

            PlayState = PlayState.Playing;
        }
Exemplo n.º 6
0
        private static PlayableItem GetStreamedItem(BaseItemDto item, List <MediaSourceInfo> mediaSources, IApiClient apiClient, long?startTimeTicks, int?maxBitrate)
        {
            var profile = new MediaBrowserTheaterProfile();

            StreamInfo info;

            if (item.IsAudio)
            {
                var options = new AudioOptions
                {
                    Context  = EncodingContext.Streaming,
                    DeviceId = apiClient.DeviceId,
                    ItemId   = item.Id,

                    // TODO: Reduce to 2 is user only has stereo speakers
                    MaxAudioChannels = 6,

                    MaxBitrate   = maxBitrate,
                    MediaSources = mediaSources,

                    Profile = profile
                };

                info = new StreamBuilder().BuildAudioItem(options);
                info.StartPositionTicks = startTimeTicks ?? 0;

                if (info.MediaSource.Protocol == MediaProtocol.File && File.Exists(info.MediaSource.Path))
                {
                    return(new PlayableItem
                    {
                        OriginalItem = item,
                        PlayablePath = info.MediaSource.Path,
                        MediaSource = info.MediaSource,
                        StreamInfo = info
                    });
                }

                return(new PlayableItem
                {
                    OriginalItem = item,
                    PlayablePath = info.ToUrl(apiClient.ServerAddress + "/mediabrowser"),
                    MediaSource = info.MediaSource,
                    StreamInfo = info
                });
            }
            else
            {
                var options = new VideoOptions
                {
                    Context  = EncodingContext.Streaming,
                    DeviceId = apiClient.DeviceId,
                    ItemId   = item.Id,

                    // TODO: Reduce to 2 is user only has stereo speakers
                    MaxAudioChannels = 6,

                    MaxBitrate   = maxBitrate,
                    MediaSources = mediaSources,

                    Profile = profile
                };

                info = new StreamBuilder().BuildVideoItem(options);
                info.StartPositionTicks = startTimeTicks ?? 0;

                if (info.MediaSource.Protocol == MediaProtocol.File && File.Exists(info.MediaSource.Path))
                {
                    return(new PlayableItem
                    {
                        OriginalItem = item,
                        PlayablePath = info.MediaSource.Path,
                        MediaSource = info.MediaSource,
                        StreamInfo = info
                    });
                }

                //info.Container = "ts";
                //info.VideoCodec = "copy";
                //info.AudioCodec = "copy";
                //info.Protocol = "http";

                //if (item.IsType("tvchannel"))
                //{
                //    info.VideoCodec = "copy";
                //}

                var playable = new PlayableItem
                {
                    OriginalItem = item,
                    PlayablePath = info.ToUrl(apiClient.ServerAddress + "/mediabrowser"),
                    MediaSource  = info.MediaSource,
                    StreamInfo   = info
                };

                if (!info.IsDirectStream)
                {
                    playable.PlayablePath += "&EnableAdaptiveBitrateStreaming=false";
                }

                return(playable);
            }
        }
        internal async void OnPlaybackStopped(PlayableItem media, long? positionTicks, TrackCompletionReason reason, int? newTrackIndex)
        {
            DisposeMount(media);

            if (reason == TrackCompletionReason.Ended || reason == TrackCompletionReason.ChangeTrack)
            {
                var nextIndex = newTrackIndex ?? (CurrentPlaylistIndex + 1);

                if (nextIndex < CurrentPlayOptions.Items.Count)
                {
                    await PlayTrack(nextIndex, null);
                    return;
                }
            }

            DisposePlayer();

            var args = new PlaybackStopEventArgs
            {
                Player = this,
                Playlist = _playlist,
                EndingMedia = media.OriginalItem,
                EndingPositionTicks = positionTicks

            };

            EventHelper.FireEventIfNotNull(PlaybackCompleted, this, args, _logger);

            _playbackManager.ReportPlaybackCompleted(args);
        }
 private void DisposeMount(PlayableItem media)
 {
     if (media.IsoMount != null)
     {
         try
         {
             media.IsoMount.Dispose();
             media.IsoMount = null;
         }
         catch (Exception ex)
         {
             _logger.ErrorException("Error unmounting iso {0}", ex, media.IsoMount.MountedPath);
         }
     }
 }
        public void Play(PlayableItem item, bool enableReclock, bool enableMadvr, bool enableXySubFilter)
        {
            _logger.Info("Playing {0}. Reclock: {1}, Madvr: {2}, xySubFilter: {3}", item.OriginalItem.Name, enableReclock, enableMadvr, enableXySubFilter);

            _item = item;

            var isDvd = (item.OriginalItem.VideoType ?? VideoType.VideoFile) == VideoType.Dvd || (item.OriginalItem.IsoType ?? IsoType.BluRay) == IsoType.Dvd && item.PlayablePath.IndexOf("http://", StringComparison.OrdinalIgnoreCase) == -1;

            Initialize(item.PlayablePath, enableReclock, enableMadvr, enableXySubFilter, isDvd);

            var hr = _mediaControl.Run();
            DsError.ThrowExceptionForHR(hr);

            PlayState = PlayState.Playing;
        }