/// <summary> /// Play media argument /// </summary> /// <param name="media">Media to play</param> public void Play(MediaBase media) { MediaLibrary.MediaItems.Clear(); MediaLibrary.MediaItems.Add(media); MediaLibrary.SelectedMedia = media; Play(); }
/// <summary> /// Play next media in media library /// </summary> public void Next() { if (MediaLibrary == null) { return; } MediaBase oldMedia = MediaLibrary.SelectedMedia; MediaLibrary.Next(); MediaBase newMedia = MediaLibrary.SelectedMedia; if (oldMedia != newMedia && myPlayer.State == VlcState.Playing) { Play(); } }
internal void Previous() { if (!Random) { UpdateMediaList(); } else { UpdateRandomMediaList(); } VlcMediaCollection collection = Random ? mediaRandomList : mediaList; MediaBase media; for (int cpt = 0; cpt < 2; cpt++) { media = collection.LastOrDefault(m => m.Status == MediaStates.Played); if (media != null) { if (SelectedMedia != null) { if (MediaItems.Contains(SelectedMedia)) { SelectedMedia.Status = collection.IndexOf(media) < collection.IndexOf(SelectedMedia) ? MediaStates.NotPlayed : MediaStates.Played; } else { collection.Remove(SelectedMedia); } } media.Status = MediaStates.Selected; SelectedMedia = media; break; } if (!Loop) { break; } if (cpt == 0) { collection. Where(m => m.Status == MediaStates.NotPlayed).ToList(). ForEach(m => m.Status = MediaStates.Played); } } }
private void UpdateRandomMediaList() { foreach (MediaBase item in mediaRandomList) { if (!mediaItems.Contains(item)) { item.Status = SelectedMedia == null ? MediaStates.Disabled : MediaStates.SelectedButDisabled; } } int beginningIndex = 0; if (SelectedMedia != null && mediaItems.Contains(SelectedMedia)) { beginningIndex = mediaRandomList.IndexOf(SelectedMedia) + 1; } for (int cpt = 0; cpt < mediaItems.Count; cpt++) { MediaBase item = mediaItems[cpt]; if (item == SelectedMedia) { continue; } if (!mediaRandomList.Contains(item)) { int index = new Random().Next(beginningIndex, mediaRandomList.Count); mediaRandomList.Insert(index, item); item.Status = MediaStates.NotPlayed; } else if (SelectedMedia != null && mediaRandomList.IndexOf(SelectedMedia) < mediaRandomList.IndexOf(item)) { item.Status = MediaStates.NotPlayed; } else if (SelectedMedia != null && mediaRandomList.IndexOf(SelectedMedia) > mediaRandomList.IndexOf(item)) { item.Status = MediaStates.Played; } else { item.Status = MediaStates.NotPlayed; } } }
/// <summary> /// Close of LibVlc and VlcControls instance /// </summary> public static void CloseAll() { if (HandleManager != null) { var mediaBases = new MediaBase[HandleManager.MediasHandles.Count]; HandleManager.MediasHandles.Keys.CopyTo(mediaBases, 0); foreach (MediaBase mediaBase in mediaBases) { mediaBase.Dispose(); } if (HandleManager.MediaPlayerHandles != null) { var mediaPlayers = new IVlcControl[HandleManager.MediaPlayerHandles.Count]; HandleManager.MediaPlayerHandles.Keys.CopyTo(mediaPlayers, 0); foreach (IVlcControl mediaPlayerHandle in mediaPlayers) { mediaPlayerHandle.Dispose(); } HandleManager.MediaPlayerHandles.Clear(); } if (InteropManager != null) { InteropManager.ReleaseInstance.Invoke(HandleManager.LibVlcHandle); } HandleManager.LibVlcHandle = IntPtr.Zero; } ErrorHandling = null; if (InteropManager == null) { return; } InteropManager.Dispose(); InteropManager = null; IsInitialized = false; }
internal void Next() { if (!Random) { UpdateMediaList(); } else { UpdateRandomMediaList(); } VlcMediaCollection collection = Random ? mediaRandomList : mediaList; if (Loop && SelectedMedia != null && collection.IndexOf(SelectedMedia) == collection.Count - 1) { collection.ToList().ForEach(m => m.Status = MediaStates.NotPlayed); } MediaBase media = collection.FirstOrDefault(m => m.Status == MediaStates.NotPlayed); if (media != null) { if (SelectedMedia != null) { if (SelectedMedia.Status == MediaStates.SelectedButDisabled) { collection.Remove(SelectedMedia); } else { SelectedMedia.Status = MediaStates.Played; } } media.Status = MediaStates.Selected; SelectedMedia = media; } }
internal MediaStatistics(MediaBase media) { myMedia = media; }
public void Play(MediaBase media) { if (DesignMode) return; //Initialize a default VlcManager if (myVlcManager == null) myVlcManager = new VlcManager(); InitVlcMediaPlayer(); if (media.Initialize(myVlcManager.VlcClient) == IntPtr.Zero) return; LibVlcMethods.libvlc_media_player_set_media(VlcMediaPlayer, media.VlcMedia); LibVlcMethods.libvlc_media_player_play(VlcMediaPlayer); }