public void UnwindToPlayer(UIStoryboardSegue sender) { var sourceViewController = sender.SourceViewController as FileListViewController; if (sourceViewController == null) { return; } var mediaItemCollection = sourceViewController.didPickMediaItems; if (mediaItemCollection != null) { collection = mediaItemCollection; player.SetQueue(collection); var playbackState = player.PlaybackState; if (playbackState == MPMusicPlaybackState.Playing) { player.Pause(); } player.NowPlayingItem = collection.Items[0]; playbackState = player.PlaybackState; player.Play(); } }
public override void MediaItemsPicked(MPMediaPickerController sender, MPMediaItemCollection mediaItemCollection) { var item = mediaItemCollection.RepresentativeItem; picker.DismissModalViewController(false); _callback?.Invoke(item?.AssetURL); }
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender) { if (sender == doneButton) { if (selectedMediaItems != null && selectedMediaItems.Count > 0) { didPickMediaItems = new MPMediaItemCollection(selectedMediaItems.ToArray()); } } }
public override void MediaItemsPicked(MPMediaPickerController sender, MPMediaItemCollection mediaItemCollection) { var items = mediaItemCollection.Items; var assetUrl = items[0].AssetURL; //NSData data = NSData.FromUrl(assetUrl); //NSUrl soundFileURL = NSUrl.CreateFileUrl(@"%@/memo.mp3", assetUrl); ////[NSURL fileURLWithPathNSString stringWithFormat: @"%@/memo.m4a", documentsDirectory]]; ; //NSData myData = NSData.FromUrl(soundFileURL); GetAssetFromUrl(assetUrl); _viewController.DismissModalViewController(true); }
/** ピッカー曲選択時のコールバックメソッド */ public override void MediaItemsPicked(MPMediaPickerController sender, MPMediaItemCollection mediaItemCollection) { System.Diagnostics.Debug.WriteLine("iOS MediaItemsPicked"); /** 選択した曲情報をplayerに設定 */ this.player.SetQueue(mediaItemCollection); /** 再生 */ player.Play(); var mediaItem = mediaItemCollection.Items[0]; /** ピッカーを閉じる */ UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null); }
public override void MediaItemsPicked(MPMediaPickerController sender, MPMediaItemCollection mediaItemCollection) { _viewController._musicPlayer.SetQueue(mediaItemCollection); _viewController.DismissModalViewControllerAnimated(true); MPMediaItem mediaItem = mediaItemCollection.Items[0]; //see MPMediaItem.h for various string property names (search for MPMediaItem.h in Mac Spotlight) string artist = mediaItem.ValueForProperty("artist").ToString(); string title = mediaItem.ValueForProperty("title").ToString(); _viewController.artistLabel.Text = artist; _viewController.titleLabel.Text = title; }
public override void MediaItemsPicked (MPMediaPickerController sender, MPMediaItemCollection mediaItemCollection) { _viewController._musicPlayer.SetQueue (mediaItemCollection); _viewController.DismissModalViewControllerAnimated (true); MPMediaItem mediaItem = mediaItemCollection.Items[0]; //see MPMediaItem.h for various string property names (search for MPMediaItem.h in Mac Spotlight) string artist = mediaItem.ValueForProperty ("artist").ToString (); string title = mediaItem.ValueForProperty ("title").ToString (); _viewController.artistLabel.Text = artist; _viewController.titleLabel.Text = title; }
private void PlatformLoad(Action <int> progressCallback) { MPMediaQuery mediaQuery = new MPMediaQuery(); var value = NSObject.FromObject(MPMediaType.Music); var type = MPMediaItem.MediaTypeProperty; var predicate = MPMediaPropertyPredicate.PredicateWithValue(value, type); mediaQuery.AddFilterPredicate(predicate); mediaQuery.GroupingType = MPMediaGrouping.Album; List <Song> songList = new List <Song>(); List <Album> albumList = new List <Album>(); for (int i = 0; i < mediaQuery.Collections.Length; i++) { MPMediaItemCollection itemCollection = mediaQuery.Collections[i]; List <Song> albumSongs = new List <Song>(itemCollection.Count); var nsAlbumArtist = itemCollection.RepresentativeItem.ValueForProperty(MPMediaItem.AlbumArtistProperty); var nsAlbumName = itemCollection.RepresentativeItem.ValueForProperty(MPMediaItem.AlbumTitleProperty); var nsAlbumGenre = itemCollection.RepresentativeItem.ValueForProperty(MPMediaItem.GenreProperty); string albumArtist = nsAlbumArtist == null ? "Unknown Artist" : nsAlbumArtist.ToString(); string albumName = nsAlbumName == null ? "Unknown Album" : nsAlbumName.ToString(); string albumGenre = nsAlbumGenre == null ? "Unknown Genre" : nsAlbumGenre.ToString(); MPMediaItemArtwork thumbnail = itemCollection.RepresentativeItem.ValueForProperty(MPMediaItem.ArtworkProperty) as MPMediaItemArtwork; var album = new Album(new SongCollection(albumSongs), albumName, new Artist(albumArtist), new Genre(albumGenre), thumbnail); albumList.Add(album); for (int j = 0; j < itemCollection.Count; j++) { var nsArtist = itemCollection.Items[j].ValueForProperty(MPMediaItem.ArtistProperty); var nsTitle = itemCollection.Items[j].ValueForProperty(MPMediaItem.TitleProperty); var nsGenre = itemCollection.Items[j].ValueForProperty(MPMediaItem.GenreProperty); var assetUrl = itemCollection.Items[j].ValueForProperty(MPMediaItem.AssetURLProperty) as NSUrl; if (nsTitle == null || assetUrl == null) // The Asset URL check will exclude iTunes match items from the Media Library that are not downloaded, but show up in the music app { continue; } string artist = nsArtist == null ? "Unknown Artist" : nsArtist.ToString(); string title = nsTitle.ToString(); string genre = nsGenre == null ? "Unknown Genre" : nsGenre.ToString(); TimeSpan duration = TimeSpan.FromSeconds(((NSNumber)itemCollection.Items[j].ValueForProperty(MPMediaItem.PlaybackDurationProperty)).FloatValue); var song = new Song(album, new Artist(artist), new Genre(genre), title, duration, itemCollection.Items[j], assetUrl); albumSongs.Add(song); songList.Add(song); } } albumCollection = new AlbumCollection(albumList); songCollection = new SongCollection(songList); /*_playLists = new PlaylistCollection(); * * MPMediaQuery playlists = new MPMediaQuery(); * playlists.GroupingType = MPMediaGrouping.Playlist; * for (int i = 0; i < playlists.Collections.Length; i++) * { * MPMediaItemCollection item = playlists.Collections[i]; * Playlist list = new Playlist(); * list.Name = playlists.Items[i].ValueForProperty(MPMediaPlaylistPropertyName).ToString(); * for (int k = 0; k < item.Items.Length; k++) * { * TimeSpan time = TimeSpan.Parse(item.Items[k].ValueForProperty(MPMediaItem.PlaybackDurationProperty).ToString()); * list.Duration += time; * } * _playLists.Add(list); * }*/ }
public override void MediaItemsPicked(MPMediaPickerController sender, MPMediaItemCollection mediaItemCollection) { _playBackScreen._musicPlayer.SetQueue (mediaItemCollection); _playBackScreen.DismissViewController (true, null); MPMediaItem mediaItem = mediaItemCollection.Items [0]; try{ _playBackScreen.artistLbl.Text = mediaItem.AlbumArtist.ToString(); } catch{ _playBackScreen.artistLbl.Text = "No artisit"; } _playBackScreen.titleLbl.Text = mediaItem.Title; _playBackScreen.playPauseBtn.Enabled = true; _playBackScreen.positionSkipBtn.Enabled = true; double fileLengthRaw = mediaItem.PlaybackDuration; int fileLengthInt = Convert.ToInt32 (fileLengthRaw); string fileLengthDisplay = string.Format ("{0:##}:{1:00}:{2:00}", fileLengthInt/ 3600, (fileLengthInt / 60) % 60, fileLengthInt % 60); _playBackScreen.lengthLbl.Text = fileLengthDisplay; _playBackScreen.positionSld.MaxValue = (float)(fileLengthRaw); }
public void BeginPlayback(MPMediaItemCollection itemCollection) { MusicPlayerController.SetQueue(itemCollection); MusicPlayerController.Play(); }