public SetIndexAsCurrent ( int index ) : void | ||
index | int | |
return | void |
public async Task PlayNext() { await RaiseMediaFileFailedEventOnException(async() => { if (MediaQueue.HasNext()) { MediaQueue.SetNextAsCurrent(); await PlayCurrent(); } else { MediaQueue.SetIndexAsCurrent(0); await PrepareCurrentAndThen(async() => { await CurrentPlaybackManager.Play(); await CurrentPlaybackManager.Pause(); await Seek(TimeSpan.Zero); }); OnMediaFileChanged(this, new MediaFileChangedEventArgs(CurrentMediaFile)); } }); }
public async Task PlayNext() { try { if (MediaQueue.HasNext()) { //await CurrentPlaybackManager.Pause(); MediaQueue.SetNextAsCurrent(); var beforePlayTask = _onBeforePlay?.Invoke(_currentMediaFile); if (beforePlayTask != null) { await beforePlayTask; } await Task.WhenAll( CurrentPlaybackManager.Play(_currentMediaFile), GetMediaInformation(new[] { _currentMediaFile })); } else { await CurrentPlaybackManager.Pause(); MediaQueue.SetIndexAsCurrent(0); OnMediaFileChanged(this, new MediaFileChangedEventArgs(MediaQueue.Current)); } } catch (Exception ex) { OnMediaFileFailed(CurrentPlaybackManager, new MediaFileFailedEventArgs(ex, _currentMediaFile)); throw; } }
/// <summary> /// Adds all MediaFiles to the Queue and starts playing the first item /// </summary> /// <param name="mediaFiles"></param> /// <returns></returns> public async Task Play(IEnumerable <IMediaFile> mediaFiles) { MediaQueue.Clear(); MediaQueue.AddRange(mediaFiles); // Play from index 0 MediaQueue.SetIndexAsCurrent(0); await PlayCurrent(); MediaNotificationManager?.StartNotification(CurrentMediaFile); }
public async Task PlayNext() { if (MediaQueue.HasNext()) { await CurrentPlaybackManager.Stop(); MediaQueue.SetNextAsCurrent(); await Task.WhenAll( CurrentPlaybackManager.Play(_currentMediaFile), GetMediaInformation(new[] { _currentMediaFile })); } else { // If you don't have a next song in the queue, stop and show the meta-data of the first song. //TODO: Shouldn't we Pause here instead of stop? Stop should shut down everything await CurrentPlaybackManager.Stop(); MediaQueue.SetIndexAsCurrent(0); } }
public async Task PlayByPosition(int index) { MediaQueue.SetIndexAsCurrent(index); await Play(CurrentMediaFile); }
public void Insert_OutOfRange() { var queue = new MediaQueue(); var tracks = new[] { new MediaFile(), }; queue.AddRange(tracks); queue.SetIndexAsCurrent(0); IList<NotifyCollectionChangedEventArgs> collectionChangedEvents = new List<NotifyCollectionChangedEventArgs>(); IList<PropertyChangedEventArgs> propertyChangedEvents = new List<PropertyChangedEventArgs>(); queue.CollectionChanged += (sender, e) => collectionChangedEvents.Add(e); queue.PropertyChanged += (sender, e) => propertyChangedEvents.Add(e); Assert.Throws<ArgumentOutOfRangeException>(() => { queue.Insert(2, new MediaFile()); }); Assert.AreEqual(1, queue.Count); Assert.AreEqual(tracks[0], queue.Current); Assert.AreEqual(0, queue.Index); Assert.AreEqual(RepeatType.None, queue.Repeat); Assert.AreEqual(false, queue.Shuffle); Assert.AreEqual(0, propertyChangedEvents.Count); Assert.AreEqual(0, collectionChangedEvents.Count); }
public void Insert_PreCurrent() { var queue = new MediaQueue(); var tracks = new[] { new MediaFile(), }; queue.AddRange(tracks); queue.SetIndexAsCurrent(0); IList<NotifyCollectionChangedEventArgs> collectionChangedEvents = new List<NotifyCollectionChangedEventArgs>(); IList<PropertyChangedEventArgs> propertyChangedEvents = new List<PropertyChangedEventArgs>(); queue.CollectionChanged += (sender, e) => collectionChangedEvents.Add(e); queue.PropertyChanged += (sender, e) => propertyChangedEvents.Add(e); queue.Insert(0, new MediaFile()); Assert.AreEqual(2, queue.Count); Assert.AreEqual(tracks[0], queue.Current); Assert.AreEqual(1, queue.Index); Assert.AreEqual(RepeatType.None, queue.Repeat); Assert.AreEqual(false, queue.Shuffle); Assert.AreEqual(0, propertyChangedEvents.Where(e => e.PropertyName == "Current").Count()); Assert.AreEqual(1, propertyChangedEvents.Where(e => e.PropertyName == "Index").Count()); Assert.AreEqual(1, propertyChangedEvents.Where(e => e.PropertyName == "Count").Count()); Assert.AreEqual(2, propertyChangedEvents.Count); Assert.AreEqual(1, collectionChangedEvents.Where(e => e.NewItems?.Count == 1 && e.OldItems == null).Count()); Assert.AreEqual(1, collectionChangedEvents.Count); }
public void SetNotCurrent() { var queue = new MediaQueue(); var tracks = new[] { new MediaFile(), new MediaFile(), new MediaFile(), }; queue.AddRange(tracks); queue.SetIndexAsCurrent(1); IList<NotifyCollectionChangedEventArgs> collectionChangedEvents = new List<NotifyCollectionChangedEventArgs>(); IList<PropertyChangedEventArgs> propertyChangedEvents = new List<PropertyChangedEventArgs>(); queue.CollectionChanged += (sender, e) => collectionChangedEvents.Add(e); queue.PropertyChanged += (sender, e) => propertyChangedEvents.Add(e); queue[0] = new MediaFile(); Assert.AreEqual(3, queue.Count); Assert.AreEqual(tracks[1], queue.Current); Assert.AreEqual(1, queue.Index); Assert.AreEqual(RepeatType.None, queue.Repeat); Assert.AreEqual(RepeatType.None, queue.Shuffle); Assert.AreEqual(0, propertyChangedEvents.Count); Assert.AreEqual(1, collectionChangedEvents.Where(e => e.NewItems?.Count == 1 && e.OldItems?.Count == 1).Count()); Assert.AreEqual(1, collectionChangedEvents.Count); }