public PlayableItemWrapper(IPlayableItem playableItem) { _playableItem = playableItem; this.AudioGain = _playableItem.AudioGain; this.FilePath = _playableItem.FilePath; this.PlayRange = _playableItem.PlayRange; }
internal void Preview(IPlayableItem playableItem) { if (_playableItem == playableItem) { return; } if (_player.Status != PreviewPlayerStatus.Closed) { if (_cgItems != null) { _player.Detach(_cgItems); _cgItems = null; } _player.Close(); } if (_playableItem != null) { _playableItem.PreviewClosing -= PlayableItem_PreviewClosing; } if (playableItem != null && !string.IsNullOrEmpty(playableItem.FilePath) && System.IO.File.Exists(playableItem.FilePath)) { _playableItem = playableItem; } else { _playableItem = null; } if (_playableItem != null) { _playableItem.PreviewClosing += PlayableItem_PreviewClosing; SetAudioGain(_playableItem.AudioGain, false); _player.Open(_playableItem); this.MaxPosition = _player.Duration; this.PlayRange = _playableItem.PlayRange; var withCG = _playableItem as IPlayableItemWithCG; if (withCG != null && withCG.CGItems != null && withCG.CGItems.Count > 0) { _cgItems = withCG.CGItems.Clone(); } if (_cgItems != null) { _player.Attach(_cgItems); } this.Play(); this.Pause(); } }
public static string GetId(this IPlayableItem item) { return(item switch { FullEpisode e => e.Id, FullTrack t => t.Id, _ => throw new ArgumentException() });
private static string GetUri(IPlayableItem item) { return(item switch { FullTrack t => t.Uri, FullEpisode e => e.Uri, _ => throw new ArgumentException("item has no valid Uri") });
public async Task <bool> ToggleFavorite(IPlayableItem item) { return(item switch { FullTrack track => await ToggleFavorite(track), FullEpisode episode => await ToggleFavorite(episode), _ => false });
private void Preview(IPlayableItem playableItem) { if (this.EventAggregator != null && playableItem != null) { _currentPreviewItem = playableItem; this.EventAggregator.GetEvent <PubSubEvent <IPlayableItem> >().Publish(playableItem); } }
private void RemoveItem(BindableMediaFileItem item) { if (_currentPreviewItem == item) { item.ClosePreview(); _currentPreviewItem = null; } _mediaItemCollection.Remove(item); }
/* * Determine whether item is track or podcast then display on radio */ private void UpdateInGameRadio(IPlayableItem track) { if (track.Type == ItemType.Track) { DisplaySpotifyTrackOnRadio(((FullTrack)track).Name, ((FullTrack)track).Artists[0].Name); } else { DisplaySpotifyTrackOnRadio(((FullEpisode)track).Name, ""); } }
public static string ToUri(this IPlayableItem item) { if (item is FullTrack track) { return(track.Uri); } else if (item is FullEpisode episode) { return(episode.Uri); } throw new Exception($"Unkown type to convert: {item.GetType()}"); }
public async Task Play(IPlayableItem item) { var uri = GetUri(item); var req = new PlayerResumePlaybackRequest { Uris = new List <string> { uri } }; await _spotify.Player.ResumePlayback(req); }
public void Open(IPlayableItem playableItem) { this.Close(); if (_mplaylist == null) { _mplaylist = new MPlaylistClass(); if (_mplaylistSettings.VideoFormat != null) { SetVideoFormat(_mplaylist, _mplaylistSettings.VideoFormat); } if (_mplaylistSettings.AudioFormat != null) { SetAudioFormat(_mplaylist, _mplaylistSettings.AudioFormat); } _mplaylist.PropsSet("loop", "true"); _mplaylist.OnEvent += MFile_OnEvent; _cgManager = new CGManager(_mplaylist); //_mplaylist.FileRateSet(_rate); } //_fileName = fileName; _playableItem = playableItem; //_fileName = _playableItem.FilePath; int index = -1; _mplaylist.PlaylistAdd(null, _playableItem.FilePath, "", ref index, out _mitem); _mplaylist.ObjectStart(null); _mplaylist.FileRateSet(_rate); SetAudioGain((MItemClass)_mitem, _playableItem.AudioGain); double dblIn = 0.0, dblOut = 0.0, dblDuration = 0.0; _mplaylist.FileInOutGet(out dblIn, out dblOut, out dblDuration); //_mitem.FileInOutGet(out dblIn, out dblOut, out dblDuration); this.Duration = dblDuration; string name = null; _mplaylist.ObjectNameGet(out name); this.Name = name; this.Status = PreviewPlayerStatus.Stopped; OnOpened(); }
private async void PlayingItemChanged(IPlayableItem newPlayingItem) { if (newPlayingItem == null) { // No new item playing, reset UI UpdatePlayerInfo("No track playing", "No track playing", ""); SetLibraryBtnIsLiked(false); _currentProgressSlider.value = 0; _totalProgressText.text = _currentProgressText.text = "00:00"; } else { if (newPlayingItem.Type == ItemType.Track) { if (newPlayingItem is FullTrack track) { // Update player information with track info string allArtists = S4UUtility.ArtistsToSeparatedString(", ", track.Artists); SpotifyAPI.Web.Image image = S4UUtility.GetLowestResolutionImage(track.Album.Images); UpdatePlayerInfo(track.Name, allArtists, image?.Url); // Make request to see if track is part of user's library var client = SpotifyService.Instance.GetSpotifyClient(); LibraryCheckTracksRequest request = new LibraryCheckTracksRequest(new List <string>() { track.Id }); var result = await client.Library.CheckTracks(request); if (result.Count > 0) { SetLibraryBtnIsLiked(result[0]); } } } else if (newPlayingItem.Type == ItemType.Episode) { if (newPlayingItem is FullEpisode episode) { string creators = episode.Show.Publisher; SpotifyAPI.Web.Image image = S4UUtility.GetLowestResolutionImage(episode.Images); UpdatePlayerInfo(episode.Name, creators, image?.Url); } } } }
public async void Configure(IPlayableItem featured) { labelCaption.Text = $"Rating: {featured.Rating.ToString("N2")}"; labelDescription.Text = featured.Title; // imageView.Image = null; if (String.IsNullOrEmpty(featured.ThumbnailImage)) { imageView.Image = UIImage.FromBundle("noimage"); } else { var byteImage = await ContentService.DownloadImageArrayAsync(featured.ThumbnailImage); imageView.Image = UIImage.LoadFromData(NSData.FromArray(byteImage)); } }
private void DeleteMediaItem() { if (CanDeleteMediaItem()) { var item = this.SelectedMediaItem; this.SelectedMediaItem = null; if (item == _currentPreviewItem) { _currentPreviewItem.ClosePreview(); _currentPreviewItem = null; } this.MediaFileService.DeleteMediaFile(item.Entity, App.Current.Name); _mediaItemCollection.Remove(item); //_saveMediaItemsCommand.RaiseCanExecuteChanged(); } }
private void SearchMediaItems(RequestPagingItemsEventArgs e) { if (_currentPreviewItem != null) { _currentPreviewItem.ClosePreview(); _currentPreviewItem = null; } _mediaItemCollection.Clear(); var result = MediaFileService.GetMediaFiles(this.SearchOptions, e.PagingInfo); foreach (var item in result.Items) { _mediaItemCollection.Add(new BindableFileMediaItem(item, this.ResolvePath(item.FileName))); } e.Result = result; }
private void Preview(IPlayableItem playableItem) { if (/*_eventAggregator != null && */ playableItem != null) { _currentPreviewItem = playableItem; this.PreviewInteractionRequest.Raise(new PreviewRequestConfirmation(playableItem) { Title = "预览", PlayItemEditorFactory = this }, (c) => { if (c.Confirmed) { } playableItem.ClosePreview(); }); //_eventAggregator.GetEvent<PubSubEvent<IPlayableItem>>().Publish(playableItem); } }
private void Preview(IPlayableItem playableItem) { if (_playableItem == playableItem) { return; } if (_player.Status != PreviewPlayerStatus.Closed) { _player.Close(); } if (_playableItem != null) { _playableItem.PreviewClosing -= PlayableItem_PreviewClosing; } if (playableItem != null && !string.IsNullOrEmpty(playableItem.FilePath) && System.IO.File.Exists(playableItem.FilePath)) { _playableItem = playableItem; } else { _playableItem = null; } if (_playableItem != null) { _playableItem.PreviewClosing += PlayableItem_PreviewClosing; this.PlayRange = _playableItem.PlayRange; SetAudioGain(_playableItem.AudioGain, false); _player.Open(_playableItem); this.Play(); this.Pause(); } }
public void ChangePlayRange(IPlayableItem playItem, PlayRange newRange) { this.ChangePlayRange(playItem.PlayItem, newRange); }
internal void Preview(IPlayableItem playableItem) { _viewModel.Preview(playableItem); }
private async void FetchLatestPlayer() { if (_client != null) { // get the current context on this run CurrentlyPlayingContext newContext = await _client.Player.GetCurrentPlayback(); // Check if not null if (newContext != null && newContext.Item != null) { // Check and cast the item to the correct type if (newContext.Item.Type == ItemType.Track) { FullTrack currentTrack = newContext.Item as FullTrack; // No previous track or previous item was different type if (_currentItem == null || (_currentItem != null && _currentItem is FullEpisode episode)) { Debug.Log($"No prev track or new type | -> '{S4UUtility.GetTrackString(currentTrack)}'"); _currentItem = currentTrack; OnPlayingItemChanged?.Invoke(_currentItem); } else if (_currentItem != null && _currentItem is FullTrack lastTrack) { // Check if track name & artists aren't the same if (lastTrack.Name != currentTrack.Name || S4UUtility.HasArtistsChanged(lastTrack.Artists, currentTrack.Artists)) { Debug.Log($"Track to new Track | '{S4UUtility.GetTrackString(lastTrack)}' -> '{S4UUtility.GetTrackString(currentTrack)}'"); _currentItem = currentTrack; OnPlayingItemChanged?.Invoke(_currentItem); } } } else if (newContext.Item.Type == ItemType.Episode) { FullEpisode currentEpisode = newContext.Item as FullEpisode; // If no previous item or current item is different type if (_currentItem == null || (_currentItem != null && _currentItem is FullTrack track)) { Debug.Log($"No prev episode or new type | -> '{currentEpisode.Show.Publisher} {currentEpisode.Name}'"); _currentItem = currentEpisode; OnPlayingItemChanged?.Invoke(_currentItem); } else if (_currentItem != null && _currentItem is FullEpisode lastEpisode) { if (lastEpisode.Name != currentEpisode.Name || lastEpisode.Show?.Publisher != currentEpisode.Show?.Publisher) { Debug.Log($"Episode to new Episode | '{lastEpisode.Show.Publisher} {lastEpisode.Name}' -> '{currentEpisode.Show.Publisher} {currentEpisode.Name}'"); _currentItem = currentEpisode; OnPlayingItemChanged?.Invoke(_currentItem); } } } } else { // No context or null current playing item // If previous item has been set if (_currentItem != null) { Debug.Log($"Context null | '{(_currentItem.Type == ItemType.Track ? (_currentItem as FullTrack).Name : (_currentItem as FullEpisode).Name)}' -> ?"); _currentItem = null; OnPlayingItemChanged?.Invoke(null); } } _currentContext = newContext; } else { // If no client but has a previous item, invoke event if (_currentItem != null) { _currentItem = null; OnPlayingItemChanged?.Invoke(null); } } }
public async Task <bool> IsFavorite(IPlayableItem item) { var ids = new[] { item.GetId() }; return((await _spotify.Library.CheckTracks(new LibraryCheckTracksRequest(ids))).FirstOrDefault()); }
public PreviewRequestConfirmation(IPlayableItem playableItem) { this.PlayableItem = playableItem; }
protected virtual void PlayingItemChanged(IPlayableItem item) { // Override me. }