static void AddToLibrary(ActionSheet controller, MediaItemBase item) { if (!ShouldShowAddToLibrary(item)) { return; } controller.Add("Add to Library", async() => { var onlineSong = item as OnlineSong; if (onlineSong?.TrackData?.ServiceType == ServiceType.YouTube) { //Prompt for meta data var editor = new SongTagEditor { Song = onlineSong }; await GetCurrentViewController().PresentViewControllerAsync(new UINavigationController(editor), true); var s = await editor.GetValues(); if (!s) { return; } } var success = await MusicManager.Shared.AddToLibrary(item); if (!success) { App.ShowAlert("Error", "There was an error please try again"); } }); }
public async Task <string> GetArtwork(MediaItemBase item) { var album = item as Album; if (album != null) { return(await GetArtwork(album)); } var song = item as Song; if (song != null) { return(await GetArtwork(song)); } var artist = item as Artist; if (artist != null) { return(await GetArtwork(artist)); } var station = item as RadioStation; if (station != null) { return(await GetArtwork(station)); } return(null); }
static bool ShouldShowAddToLibrary(MediaItemBase item) { var song = item as OnlineSong; if (song != null) { var service = ApiManager.Shared.GetMusicProvider(song.TrackData.ServiceId); return(service.ServiceType == ServiceType.Google || service.ServiceType == ServiceType.YouTube); } if (item is OnlineSong || item is TempSong) { return(true); } if (item is OnlineAlbum) { return(true); } if (item is OnlinePlaylist) { return(true); } if (item is OnlineRadioStation) { return(true); } var radio = item as RadioStation; if (radio != null) { return(!radio.IsIncluded); } return(false); }
static void AddRadioStationButton(ActionSheet controller, MediaItemBase item) { //TODO check if we can add station to the item; if (!SouldShowStartRadio(item)) { return; } controller.Add("Start Radio Station", async() => { using (new Spinner("Creating Station")) { try { var station = await MusicManager.Shared.CreateRadioStation(item); if (station != null) { PlaybackManager.Shared.Play(station); } else { App.ShowAlert("Error", "There was an error creating the radio station"); } } catch (Exception ex) { LogManager.Shared.Report(ex); } } }); }
public async Task <RadioStation> CreateRadioStation(MediaItemBase item) { try { var song = item as Song; if (song != null) { return(await CreateRadioStation(song)); } var album = item as Album; if (album != null) { return(await CreateRadioStation(album)); } var artist = item as Artist; if (artist != null) { return(await CreateRadioStation(artist)); } var station = item as OnlineRadioStation; if (station != null) { var provider = ApiManager.Shared.GetMusicProvider <GoogleMusicProvider>(ServiceType.Google); return(await provider.CreateRadioStation(station.Name, station.StationSeeds.FirstOrDefault())); } } catch (Exception ex) { LogManager.Shared.Report(ex); } return(null); }
public virtual async void UpdateValues(MediaItemBase item) { TextView.TopLabel.StringValue = item?.Name ?? ""; if (item?.Name?.Contains("Peggy ") == true) { Console.WriteLine("foo"); } TextView.BottomLabel.StringValue = item?.DetailText ?? ""; var width = (float)ImageView.Bounds.Width; var image = await item.GetLocalImage(width); try{ if (image != null) { ImageView.Image = image; } else { var artUrl = await ArtworkManager.Shared.GetArtwork(item); if (!string.IsNullOrWhiteSpace(artUrl)) { ImageView.SetImage(new Foundation.NSUrl(artUrl)); } else { ImageView.Image = Images.GetDefaultAlbumArt(width); } } } catch (Exception ex) { Console.WriteLine(ex); } }
async void UpdateArtwork(MediaItemBase item) { if (item == null) { return; } var urlTask = item.GetArtworkUrl(); if (!urlTask.IsCompleted) { Image.Source = Images.DefaultAlbumArt; } var url = await urlTask; if (item != BindingContext) { return; } if (string.IsNullOrWhiteSpace(url)) { return; } Image.Source = new UriImageSource { Uri = new Uri(url) }; }
public async void ToggleOffline (MediaItemBase item) { LogManager.Shared.Log ("Toggle Offline", item); var shouldBeLocal = !(item.ShouldBeLocal () || item.OfflineCount > 0); if (shouldBeLocal && (item is TempSong || item is TempAlbum || item is OnlineSong || item is OnlineAlbum)) { await MusicManager.Shared.AddToLibrary (item); } var song = item as Song; if (song != null) { await ToggleOffline (song, shouldBeLocal); return; } var album = item as Album; if (album != null) { await ToggleOffline (album, shouldBeLocal); return; } var artist = item as Artist; if (artist != null) { await ToggleOffline (artist, shouldBeLocal); return; } var playlist = item as Playlist; if (playlist != null) { await ToggleOffline (playlist, shouldBeLocal); } }
static void AddOfflineButtons(ActionSheet controller, MediaItemBase item) { if (item is RadioStation) { return; } var song = item as Song; if (song != null) { bool canOffline = false; foreach (var serviceType in song.ServiceTypes) { switch (serviceType) { case ServiceType.iPod: case ServiceType.FileSystem: return; case ServiceType.Amazon: case ServiceType.DropBox: case ServiceType.Google: canOffline = true; break; } } if (!canOffline) { return; } } var localTitle = item.ShouldBeLocal() || item.OfflineCount > 0 ? "Remove from Device" : "Download to Device"; controller.Add(localTitle, () => { OfflineManager.Shared.ToggleOffline(item); }); }
public string[] GetServiceTypes(MediaItemBase item) { var onlineSong = item as OnlineSong; if (onlineSong != null) { return(new[] { onlineSong.TrackData.ServiceId }); } var onlinePlaylist = item as OnlinePlaylist; if (onlinePlaylist != null) { return(new[] { onlinePlaylist.ServiceId }); } string column = ""; if (item is Song) { column = "SongId"; } else if (item is Album) { column = "AlbumId"; } else if (item is Artist) { column = "ArtistId"; } if (!string.IsNullOrWhiteSpace(column)) { var items = Database.Main.Query <ServiceIdHolder>($"select distinct ServiceId from Track where {column} = ? union select distinct ServiceId from TempTrack where {column} = ?", item.Id, item.Id) .ToArray(); return(items?.Select(x => x.ServiceId).ToArray() ?? new string[0]); } var playlist = item as Playlist; if (playlist != null) { return new[] { playlist.ServiceId } } ; var radio = item as RadioStation; if (radio != null) { return new[] { radio.ServiceId } } ; return(new string[0]); }
static bool ShouldRemoveFromLibrary(MediaItemBase item) { var radio = item as RadioStation; if (radio != null) { return(radio.IsIncluded); } return(false); }
static bool ShouldShowPlayVideoButton(MediaItemBase item) { var song = item as Song; if (song == null) { return(false); } return(song.HasVideo); }
static void AddShuffleButton(ActionSheet controller, MediaItemBase item) { if (!ShouldShowShuffle(item)) { return; } controller.Add("Shuffle", () => { Settings.ShuffleSongs = true; PlaybackManager.Shared.Play(item); }); }
static bool ShouldShowPlayNowButton(MediaItemBase item) { if (item is Song) { return(false); } if (item is RadioStation) { return(false); } return(true); }
static bool ShouldShowQueueButtons(MediaItemBase item) { if (item is Playlist) { return(false); } if (item is RadioStation) { return(false); } return(true); }
static bool ShouldShowShuffle(MediaItemBase item) { if (item is Song) { return(false); } if (item is RadioStation) { return(false); } return(true); }
public async Task AddtoQueue(MediaItemBase item) { var onlineSong = item as OnlineSong; if (onlineSong != null) { await MusicManager.Shared.AddTemp(onlineSong); } var song = item as Song; if (song != null) { AddToQueue(song); return; } var artist = item as Artist; if (artist != null) { var songs = await MusicManager.Shared.GetSongs(artist); await AddToQueue(songs); return; } var album = item as Album; if (album != null) { var songs = await MusicManager.Shared.GetSongs(album); await AddToQueue(songs); return; } var genre = item as Genre; if (genre != null) { var songs = await MusicManager.Shared.GetSongs(genre); await AddToQueue(songs); return; } App.ShowNotImplmented(new Dictionary <string, string> { { "Media Type", item?.GetType().ToString() } }); }
static void AddRemoveFromLibrary(ActionSheet controller, MediaItemBase item) { if (!ShouldRemoveFromLibrary(item)) { return; } controller.Add("Remove from Library", async() => { var success = await MusicManager.Shared.Delete(item); //TODO: Show Alert Console.WriteLine(success); }); }
public static async Task LoadFromItem(this NSImageView imageView, MediaItemBase item, float imageWidth, NSImage defaultImage = null) { try{ if (defaultImage == null) { defaultImage = Images.GetDefaultAlbumArt(imageWidth); } if (imageView.Identifier != item?.Id) { imageView.Image = defaultImage; } if (item == null) { return; } imageView.Identifier = item.Id; var image = await item.GetLocalImage(imageWidth); if (imageView.Identifier != item.Id) { return; } if (image != null) { imageView.Image = image; } else { var artUrl = await ArtworkManager.Shared.GetArtwork(item); if (imageView.Identifier != item.Id) { return; } if (string.IsNullOrWhiteSpace(artUrl)) { return; } var bitmap = (await BlobCache.LocalMachine.LoadImageFromUrl(artUrl, desiredWidth: imageWidth)); if (imageView.Identifier != item.Id) { return; } imageView.Image = bitmap.ToNative(); } } catch (Exception ex) { Console.WriteLine(ex); } }
public ActionSheet CreateController(MediaItemBase song) { var controller = new ActionSheet(song.Name, song.DetailText); AddPlaybackButtons(controller, song); AddShuffleButton(controller, song); AddPlaylistButtons(controller, song); AddRadioStationButton(controller, song); AddToLibrary(controller, song); AddRemoveFromLibrary(controller, song); AddOfflineButtons(controller, song); controller.Add("Cancel", null, true); return(controller); }
static void AddNavigateTo(ActionSheet controller, MediaItemBase item) { var song = item as Song; if (song == null) { return; } if (!string.IsNullOrWhiteSpace(song.AlbumId)) { controller.Add("Go to Album", () => { NotificationManager.Shared.ProcGoToAlbum(song.AlbumId); }); } controller.Add("Go to Artist", () => { NotificationManager.Shared.ProcGoToArtist(song.ArtistId); }); }
public static async Task <NSImage> GetLocalImage(this MediaItemBase item, double width) { try { List <Track> tracks = null; if (item is Song) { tracks = await Database.Main.TablesAsync <Track>() .Where(x => x.ServiceType == ServiceType.FileSystem && x.SongId == item.Id) .ToListAsync(); } else if (item is Album) { tracks = await Database.Main.TablesAsync <Track>() .Where(x => x.ServiceType == ServiceType.FileSystem && x.AlbumId == item.Id) .ToListAsync(); } else if (item is Artist) { tracks = await Database.Main.TablesAsync <Track>() .Where(x => x.ServiceType == ServiceType.FileSystem && x.ArtistId == item.Id) .ToListAsync(); } if (tracks != null) { foreach (var track in tracks) { var image = await track.GetImage(width); if (image != null) { return(image); } } } } catch (Exception ex) { LogManager.Shared.Report(ex); } return(null); }
public async Task <bool> AddToLibrary(MediaItemBase item) { var onlineSong = item as OnlineSong; if (onlineSong != null) { return(await AddToLibrary(onlineSong)); } var tempSong = item as TempSong; if (tempSong != null) { return(await AddToLibrary(tempSong)); } var album = item as OnlineAlbum; if (album != null) { return(await AddToLibrary(album)); } var plist = item as OnlinePlaylist; if (plist != null) { return(await AddToLibrary(plist)); } var onlineState = item as OnlineRadioStation; if (onlineState != null) { return(await AddToLibrary(onlineState)); } var radio = item as RadioStation; if (radio != null) { return(await AddToLibrary(radio)); } App.ShowNotImplmented(); return(false); }
public async Task <bool> Delete(MediaItemBase item) { var radio = item as RadioStation; if (radio != null) { return(await Delete(radio)); } var playlist = item as Playlist; if (playlist != null) { return(await Delete(playlist)); } return(false); }
async Task <NSImage> GetImage(MediaItemBase item, double imageWidth, NSImage defaultImage = null) { try { if (item == null) { return(defaultImage ?? Images.GetDefaultAlbumArt(imageWidth)); } var image = await item.GetLocalImage(imageWidth); if (image != null) { return(image); } else { var artUrl = await ArtworkManager.Shared.GetArtwork(item); if (string.IsNullOrWhiteSpace(artUrl)) { return(defaultImage); } var tcs = new TaskCompletionSource <NSImage>(); var imageManager = SDWebImageManager.SharedManager.ImageDownloader.DownloadImage(new NSUrl(artUrl), SDWebImageDownloaderOptions.HighPriority, (receivedSize, expectedSize, u) => { }, (i, data, error, finished) => { if (error != null) { tcs.TrySetException(new Exception(error.ToString())); } else { tcs.TrySetResult(i); } }); return(await tcs.Task); } } catch (Exception ex) { Console.WriteLine(ex); } return(defaultImage); }
static bool ShouldShowAddPlaylist(MediaItemBase item) { if (item is Playlist) { return(false); } if (item is RadioStation) { return(false); } var song = item as OnlineSong; if (song != null) { var service = ApiManager.Shared.GetMusicProvider(song.TrackData.ServiceId); return(service.Capabilities.Contains(MediaProviderCapabilities.Playlists)); } return(true); }
static void AddOfflineButtons(ActionSheet controller, MediaItemBase item) { if (item is RadioStation || item is AutoPlaylist) { return; } var song = item as Song; if (song != null) { bool canOffline = song.ServiceTypes.Any(x => AllowedOffLineTypes.Contains(x)); if (!canOffline) { return; } } var localTitle = item.ShouldBeLocal() || item.OfflineCount > 0 ? "Remove from Device" : "Download to Device"; controller.Add(localTitle, () => { OfflineManager.Shared.ToggleOffline(item); }); }
public List <(string Title, Func <Task <bool> > Action)> CreatePopoptions(MediaItemBase mediaItem) { var actions = new List <(string Title, Func <Task <bool> > Action)> { (Strings.Play, () => Play(mediaItem)), (Strings.Shuffle, () => Shuffle(mediaItem)), }; bool hasQueue = !(mediaItem is RadioStation radio) && !(mediaItem is Playlist playlist); if (hasQueue) { actions.Add((Strings.PlayNext, () => PlayNext(mediaItem))); actions.Add((Strings.AddToQueue, () => Queue(mediaItem))); actions.Add((Strings.AddingToPlaylist, () => AddToPlaylist(mediaItem))); } if (SouldShowStartRadio(mediaItem)) { actions.Add((Strings.StartRadioStation, () => StartRadioStation(mediaItem))); } return(actions); }
public async Task <bool> StartRadioStation(MediaItemBase item) { using (new Spinner(Strings.CreatingStation)) { try { var station = await MusicManager.Shared.CreateRadioStation(item); if (station != null) { await PlaybackManager.Shared.Play(station); return(true); } else { App.ShowAlert(Strings.RenameError, Strings.ErrorCreatingStation); } } catch (Exception ex) { LogManager.Shared.Report(ex); } } return(false); }
public void Log(string message, MediaItemBase mediaItem, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) { try { var dictionary = new Dictionary <string, string>() { { "Media ID", mediaItem?.Id ?? "NULL" }, { "Media Title", mediaItem?.Name ?? "NULL" }, { "Media Type", mediaItem?.GetType().Name ?? "NULL" }, { "Method", memberName }, { "File", CleansFilePath(sourceFilePath) }, { "Line number", sourceLineNumber.ToString() }, }; TrackEvent(message, dictionary); } catch (Exception ex) { Console.WriteLine(ex); } }