public MediaItem MoveAndGetNext() { lock (_syncObj) { if (_repeatMode == RepeatMode.One) { return(Current); } // Skip forward for multi-resource media items if (HasNextResourceIndex) { Current.ActiveResourceLocatorIndex++; return(Current); } if (_currentPlayIndex < _itemList.Count) { _currentPlayIndex++; } if (AllPlayed && _repeatMode == RepeatMode.All) { _currentPlayIndex = 0; } PlaylistMessaging.SendPlaylistMessage(PlaylistMessaging.MessageType.CurrentItemChange, _playerContext); return(Current); } }
public MediaItem MoveAndGetPrevious() { lock (_syncObj) { if (_repeatMode == RepeatMode.One) { return(Current); } // Skip back for multi-resource media items if (HasPreviousResourceIndex) { Current.ActiveResourceLocatorIndex--; return(Current); } int oldPlayIndex = _currentPlayIndex; if (_currentPlayIndex > -1) { _currentPlayIndex--; } if (_currentPlayIndex == -1 && _repeatMode == RepeatMode.All) { _currentPlayIndex = _itemList.Count - 1; } if (_currentPlayIndex != oldPlayIndex) { PlaylistMessaging.SendPlaylistMessage(PlaylistMessaging.MessageType.CurrentItemChange, _playerContext); } return(Current); } }
protected void SetCurrentPlayIndexByItemIndex(int currentItemIndex) { lock (_syncObj) if (currentItemIndex == -1) { _currentPlayIndex = -1; } else { // Find current played item in shuffled index list if (_playIndexList == null) { _playIndexList = BuildPlayIndexList(); } foreach (int i in _playIndexList) { if (_playIndexList[i] == currentItemIndex) { _currentPlayIndex = i; break; } } } if (!InBatchUpdateMode) { PlaylistMessaging.SendPlaylistMessage(PlaylistMessaging.MessageType.CurrentItemChange, _playerContext); } }
public void ResetStatus() { lock (_syncObj) { _currentPlayIndex = -1; _playIndexList = null; PlaylistMessaging.SendPlaylistMessage(PlaylistMessaging.MessageType.PropertiesChange, _playerContext); PlaylistMessaging.SendPlaylistMessage(PlaylistMessaging.MessageType.CurrentItemChange, _playerContext); } }
public void RemoveRange(int fromIndex, int toIndex) { lock (_syncObj) { if (fromIndex < 0) { fromIndex = 0; } if (toIndex > _itemList.Count) { toIndex = _itemList.Count; } if (toIndex <= fromIndex) { return; } for (int i = toIndex - 1; i >= fromIndex; i--) { _itemList.RemoveAt(i); } if (!InBatchUpdateMode) { PlaylistMessaging.SendPlaylistMessage(PlaylistMessaging.MessageType.PlaylistUpdate, _playerContext); } if (_playIndexList == null) { return; } // Adapt play index list int removeCount = toIndex - fromIndex; for (int i = _playIndexList.Count - 1; i >= 0; i--) { int playIndex = _playIndexList[i]; if (playIndex < fromIndex) { continue; } if (playIndex < toIndex) { _playIndexList.RemoveAt(i); } else { _playIndexList[i] -= removeCount; } } // Fix current play index if (_currentPlayIndex >= _playIndexList.Count) { _currentPlayIndex = 0; } } }
public void Clear() { lock (_syncObj) { _itemList.Clear(); _playIndexList = null; _currentPlayIndex = -1; if (!InBatchUpdateMode) { PlaylistMessaging.SendPlaylistMessage(PlaylistMessaging.MessageType.PlaylistUpdate, _playerContext); } } }
public void Swap(int index1, int index2) { lock (_syncObj) { if (index1 == index2) { return; } if (index1 < 0 || index1 >= _itemList.Count || index2 < 0 || index2 >= _itemList.Count) { return; } CollectionUtils.Swap(_itemList, index1, index2); if (!InBatchUpdateMode) { PlaylistMessaging.SendPlaylistMessage(PlaylistMessaging.MessageType.PlaylistUpdate, _playerContext); } if (_playIndexList == null) { // If index list isn't yet initialized, we don't need to adapt the play index positions return; } // Adapt play index list int[] piIndices = new int[2]; int numFound = 0; for (int i = 0; i < _playIndexList.Count; i++) { int tmpIndex = _playIndexList[i]; if (tmpIndex == index1 || tmpIndex == index2) { piIndices[numFound++] = i; } if (numFound == 2) { break; } } if (numFound != 2) { // Playlist and index list are out-of-sync. This should never happen... _playIndexList = BuildPlayIndexList(); _currentPlayIndex = -1; return; } int tmp = _playIndexList[piIndices[0]]; _playIndexList[piIndices[0]] = _playIndexList[piIndices[1]]; _playIndexList[piIndices[1]] = tmp; // We don't need to update the _currentPlayIndex because the change only happens on the underlaying data } }
public bool Insert(int index, MediaItem mediaItem) { lock (_syncObj) { if (index < 0 || index > _itemList.Count) { return(false); } _itemList.Insert(index, mediaItem); if (!InBatchUpdateMode) { PlaylistMessaging.SendPlaylistMessage(PlaylistMessaging.MessageType.PlaylistUpdate, _playerContext); } if (_playIndexList == null) { return(true); } // Adapt play index list... // ... patch old play indices for (int i = 0; i < _playIndexList.Count; i++) { if (_playIndexList[i] >= index) { _playIndexList[i] += 1; } } // ... and add new item if (_playMode == PlayMode.Shuffle) { // Shuffle mode: insert an index entry for the new item at a random position int insertPos = rnd.Next(_itemList.Count - 1); _playIndexList.Insert(insertPos, index); if (_currentPlayIndex > -1 && insertPos <= _currentPlayIndex) { _currentPlayIndex++; } } else { // Continuous mode: Simply add an index entry at the end of the index list _playIndexList.Add(index); } return(true); } }
public MediaItem MoveAndGetNext() { lock (_syncObj) { if (_repeatMode == RepeatMode.One) { return(Current); } if (_currentPlayIndex < _itemList.Count) { _currentPlayIndex++; } if (AllPlayed && _repeatMode == RepeatMode.All) { _currentPlayIndex = 0; } PlaylistMessaging.SendPlaylistMessage(PlaylistMessaging.MessageType.CurrentItemChange, _playerContext); return(Current); } }
public MediaItem MoveAndGetPrevious() { lock (_syncObj) { if (_repeatMode == RepeatMode.One) { return(Current); } int oldPlayIndex = _currentPlayIndex; if (_currentPlayIndex > -1) { _currentPlayIndex--; } if (_currentPlayIndex == -1 && _repeatMode == RepeatMode.All) { _currentPlayIndex = _itemList.Count - 1; } if (_currentPlayIndex != oldPlayIndex) { PlaylistMessaging.SendPlaylistMessage(PlaylistMessaging.MessageType.CurrentItemChange, _playerContext); } return(Current); } }