示例#1
0
        public static DefaultBufferingPolicy SetBandwidth(this DefaultBufferingPolicy policy, double bitsPerSecond)
        {
            if (null == policy)
            {
                throw new ArgumentNullException("policy");
            }
            if (bitsPerSecond < 100.0 || bitsPerSecond > 524288000.0)
            {
                throw new ArgumentOutOfRangeException("bitsPerSecond");
            }
            double   num1     = bitsPerSecond * 0.125;
            int      num2     = (int)Math.Round(policy.DurationStartingDone.TotalSeconds * num1);
            TimeSpan timeSpan = policy.DurationBufferingDone;
            int      num3     = (int)Math.Round(timeSpan.TotalSeconds * num1);
            double   num4     = 2.0;

            timeSpan = policy.DurationBufferingMax;
            double totalSeconds = timeSpan.TotalSeconds;
            int    num5         = (int)Math.Round(num4 * totalSeconds * num1);

            if (num2 < 1024)
            {
                num2 = 1024;
            }
            if (num3 < 1024)
            {
                num3 = 1024;
            }
            if (num5 < 524288)
            {
                num5 = 524288;
            }
            if (num3 > num5)
            {
                num3 = num5;
            }
            if (num2 > num5)
            {
                num2 = num5;
            }
            policy.BytesMinimumStarting = num2;
            policy.BytesMinimum         = num3;
            policy.BytesMaximum         = num5;
            return(policy);
        }
示例#2
0
        public MediaPlayerManager(MediaPlayer mediaPlayer, MetadataHandler metadataHandler, CancellationToken cancellationToken)
        {
            if (null == mediaPlayer)
                throw new ArgumentNullException(nameof(mediaPlayer));
            if (null == metadataHandler)
                throw new ArgumentNullException(nameof(metadataHandler));

            Debug.WriteLine("MediaPlayerManager.ctor()");

            _mediaPlayer = mediaPlayer;
            _metadataHandler = metadataHandler;
            _cancellationToken = cancellationToken;

            var parameters = MediaStreamFacadeSettings.Parameters;

            parameters.UseHttpConnection = true;
            //parameters.UseSingleStreamMediaManager = true;

            _mediaManagerParameters = new MediaManagerParameters
            {
                ProgramStreamsHandler =
                    streams =>
                    {
                        var firstAudio = streams.Streams.FirstOrDefault(x => x.StreamType.Contents == TsStreamType.StreamContents.Audio);

                        var others = null == firstAudio ? streams.Streams : streams.Streams.Where(x => x.Pid != firstAudio.Pid);
                        foreach (
                            var programStream in others)
                            programStream.BlockStream = true;
                    }
            };

            _bufferingPolicy = new DefaultBufferingPolicy
            {
                BytesMinimumStarting = 24 * 1024,
                BytesMinimum = 64 * 1024
            };

            _mediaPlayer.MediaOpened += MediaPlayerOnMediaOpened;
            _mediaPlayer.MediaEnded += MediaPlayerOnMediaEnded;
            _mediaPlayer.CurrentStateChanged += MediaPlayerOnCurrentStateChanged;
            _mediaPlayer.MediaFailed += MediaPlayerOnMediaFailed;

            _position = BackgroundSettings.Position;

            var currentTrackUrl = BackgroundSettings.Track;

            if (null == currentTrackUrl)
            {
                if (_position.HasValue)
                {
                    _position = null;
                    BackgroundSettings.Track = null;
                }

                return;
            }

            for (var i = 0; i < _tracks.Count; ++i)
            {
                var track = _tracks[i];

                if (null == track)
                    continue;

                if (track.Url == currentTrackUrl)
                {
                    _trackIndex = i;
                    return;
                }
            }

            if (_position.HasValue)
            {
                _position = null;
                BackgroundSettings.Track = null;
            }
        }