mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-16 18:42:52 -07:00
Replace foreach loop with FindIndex
This commit is contained in:
parent
1dbc91978e
commit
83333e1fe8
@ -269,18 +269,8 @@ namespace MediaBrowser.Controller.SyncPlay
|
|||||||
/// <param name="itemId">The new playing item identifier.</param>
|
/// <param name="itemId">The new playing item identifier.</param>
|
||||||
public void SetPlayingItemById(Guid itemId)
|
public void SetPlayingItemById(Guid itemId)
|
||||||
{
|
{
|
||||||
PlayingItemIndex = NoPlayingItemIndex;
|
|
||||||
|
|
||||||
var playlist = GetPlaylistInternal();
|
var playlist = GetPlaylistInternal();
|
||||||
foreach (var item in playlist)
|
PlayingItemIndex = playlist.FindIndex(item => item.ItemId.Equals(itemId));
|
||||||
{
|
|
||||||
if (item.ItemId.Equals(itemId))
|
|
||||||
{
|
|
||||||
PlayingItemIndex = playlist.IndexOf(item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LastChange = DateTime.UtcNow;
|
LastChange = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,19 +281,10 @@ namespace MediaBrowser.Controller.SyncPlay
|
|||||||
/// <returns><c>true</c> if playing item has been set; <c>false</c> if item is not in the playlist.</returns>
|
/// <returns><c>true</c> if playing item has been set; <c>false</c> if item is not in the playlist.</returns>
|
||||||
public bool SetPlayingItemByPlaylistId(string playlistItemId)
|
public bool SetPlayingItemByPlaylistId(string playlistItemId)
|
||||||
{
|
{
|
||||||
PlayingItemIndex = NoPlayingItemIndex;
|
|
||||||
|
|
||||||
var playlist = GetPlaylistInternal();
|
var playlist = GetPlaylistInternal();
|
||||||
foreach (var item in playlist)
|
PlayingItemIndex = playlist.FindIndex(item => item.PlaylistItemId.Equals(playlistItemId, StringComparison.OrdinalIgnoreCase));
|
||||||
{
|
|
||||||
if (item.PlaylistItemId.Equals(playlistItemId, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
PlayingItemIndex = playlist.IndexOf(item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LastChange = DateTime.UtcNow;
|
LastChange = DateTime.UtcNow;
|
||||||
|
|
||||||
return PlayingItemIndex != NoPlayingItemIndex;
|
return PlayingItemIndex != NoPlayingItemIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,16 +361,7 @@ namespace MediaBrowser.Controller.SyncPlay
|
|||||||
var playlist = GetPlaylistInternal();
|
var playlist = GetPlaylistInternal();
|
||||||
var playingItem = GetPlayingItem();
|
var playingItem = GetPlayingItem();
|
||||||
|
|
||||||
var oldIndex = -1;
|
var oldIndex = playlist.FindIndex(item => item.PlaylistItemId.Equals(playlistItemId, StringComparison.OrdinalIgnoreCase));
|
||||||
foreach (var item in playlist)
|
|
||||||
{
|
|
||||||
if (item.PlaylistItemId.Equals(playlistItemId, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
oldIndex = playlist.IndexOf(item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldIndex < 0)
|
if (oldIndex < 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user