Beispiel #1
0
 private void Play(MediaPlaybackList playlist)
 {
     foreach (var item in playlist.Items)
     {
         var asset = AVAsset.FromUrl(DecodeUri(item.Source.Uri));
         _player.InsertItem(new AVPlayerItem(asset), null);
     }
 }
Beispiel #2
0
 public void NullAllowedTest()
 {
     using (var player = new AVQueuePlayer()) {
         using (var item = new AVPlayerItem(NSUrl.FromString("http://example.org"))) {
             player.CanInsert(item, null);
             player.InsertItem(item, null);
         }
     }
 }
Beispiel #3
0
        protected virtual void InitializeSource()
        {
            PlaybackSession.NaturalDuration    = TimeSpan.Zero;
            PlaybackSession.PositionFromPlayer = TimeSpan.Zero;

            // Reset player
            TryDisposePlayer();

            if (Source == null)
            {
                return;
            }

            try
            {
                InitializePlayer();

                PlaybackSession.PlaybackState = MediaPlaybackState.Opening;

                _player.CurrentItem?.RemoveObserver(_observer, new NSString("duration"), _player.Handle);
                _player.CurrentItem?.RemoveObserver(_observer, new NSString("status"), _player.Handle);
                _player.CurrentItem?.RemoveObserver(_observer, new NSString("loadedTimeRanges"), _player.Handle);

                if (Source is MediaPlaybackList)
                {
                    var items = ((MediaPlaybackList)Source).Items;
                    foreach (var item in items)
                    {
                        var asset = AVAsset.FromUrl(DecodeUri(item.Source.Uri));
                        _player.InsertItem(new AVPlayerItem(asset), null);
                    }
                }
                else
                {
                    var nsAsset       = AVAsset.FromUrl(DecodeUri(((MediaSource)Source).Uri));
                    var streamingItem = AVPlayerItem.FromAsset(nsAsset);

                    _player.ReplaceCurrentItemWithPlayerItem(streamingItem);
                }

                _player.CurrentItem.AddObserver(_observer, new NSString("duration"), NSKeyValueObservingOptions.Initial, _player.Handle);
                _player.CurrentItem.AddObserver(_observer, new NSString("status"), NSKeyValueObservingOptions.New | NSKeyValueObservingOptions.Initial, _player.Handle);
                _player.CurrentItem.AddObserver(_observer, new NSString("loadedTimeRanges"), NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.New, _player.Handle);

                _player.CurrentItem.SeekingWaitsForVideoCompositionRendering = true;

                // Adapt pitch to prevent "metallic echo" when changing playback rate
                _player.CurrentItem.AudioTimePitchAlgorithm = AVAudioTimePitchAlgorithm.TimeDomain;

                MediaOpened?.Invoke(this, null);
            }
            catch (Exception ex)
            {
                OnMediaFailed(ex);
            }
        }