public async Task CreateSongAsyncTest() { // Arrange var songRepoMock = new Mock <ISongRepository>(); songRepoMock.Setup(mock => mock.CreateSongAsync(It.Is((NewSongDataDto dataDto) => ( dataDto.AlbumId == 1 && dataDto.Name == "Test" && dataDto.Duration == 1337 )))) .ReturnsAsync(new SongDataDto { Id = 1, AlbumId = 1, Name = "Test", FileName = "", Duration = 1337, }) .Verifiable(); var songCollection = new SongCollection(songRepoMock.Object, _dependencyMapper); // Act var song = await songCollection.CreateSongAsync(1, "Test", 1337); // Assert songRepoMock.Verify(); Assert.AreEqual(1, song.Id); Assert.AreEqual("Test", song.Name); Assert.AreEqual("", song.FileName); Assert.AreEqual(1337, song.Duration); }
private void PlatformLoad(Action<int> progressCallback) { var songList = new List<Song>(); var albumList = new List<Album>(); foreach (var collection in MPMediaQuery.AlbumsQuery.Collections) { var nsAlbumArtist = collection.RepresentativeItem.ValueForProperty(MPMediaItem.AlbumArtistProperty); var nsAlbumName = collection.RepresentativeItem.ValueForProperty(MPMediaItem.AlbumTitleProperty); var nsAlbumGenre = collection.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 = collection.RepresentativeItem.ValueForProperty(MPMediaItem.ArtworkProperty) as MPMediaItemArtwork; var albumSongs = new List<Song>((int)collection.Count); var album = new Album(new SongCollection(albumSongs), albumName, new Artist(albumArtist), new Genre(albumGenre), thumbnail); albumList.Add(album); foreach (var item in collection.Items) { var nsArtist = item.ValueForProperty(MPMediaItem.ArtistProperty); var nsTitle = item.ValueForProperty(MPMediaItem.TitleProperty); var nsGenre = item.ValueForProperty(MPMediaItem.GenreProperty); var assetUrl = item.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)item.ValueForProperty(MPMediaItem.PlaybackDurationProperty)).FloatValue); var song = new Song(album, new Artist(artist), new Genre(genre), title, duration, item, 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 async Task GetSongsByAlbumIdAsyncTest_ValidId_OneSong() { // Arrange SongDataDto[] result = { new SongDataDto { Id = 1, Name = "Test", FileName = "test.mp3", Duration = 1337 }, }; var songRepoMock = new Mock <ISongRepository>(); songRepoMock.Setup(mock => mock.GetSongsByAlbumId(1)) .ReturnsAsync(result) .Verifiable(); var songCollection = new SongCollection(songRepoMock.Object, _dependencyMapper); // Act var songs = (await songCollection.GetSongsByAlbumIdAsync(1)).ToArray(); // Assert songRepoMock.Verify(); Assert.AreEqual(1, songs.Length); Assert.AreEqual(1, songs[0].Id); Assert.AreEqual("Test", songs[0].Name); Assert.AreEqual("test.mp3", songs[0].FileName); Assert.AreEqual(1337, songs[0].Duration); }
public Song(string id, SongMetadata metadata, string fileId, SongCollection collection) { Id = id; Metadata = metadata; FileId = fileId; this.collection = collection; }
public MusicManager() { _SongCollection = _MediaLibrary.Songs; _MaxSong = _SongCollection.Count; // _NowPlay = 0; FileReader(); }
public override bool LoadSong(String location, String name) { MediaLibrary mediaLibrary = null; foreach (MediaSource mediaSource in MediaSource.GetAvailableMediaSources()) { if (mediaSource.MediaSourceType == MediaSourceType.LocalDevice) { mediaLibrary = new MediaLibrary(mediaSource); break; } } if (mediaLibrary == null) { return(false); } SongCollection songs = mediaLibrary.Songs; foreach (Song s in songs) { if (s.Name.Equals(name)) { useBaseSong = true; failedLoad = false; baseSong = s; return(true); } } failedLoad = true; return(false); }
public void LoadAll() { setlist = new List <Song>(); MediaLibrary mediaLibrary = null; foreach (MediaSource mediaSource in MediaSource.GetAvailableMediaSources()) { if (mediaSource.MediaSourceType == MediaSourceType.LocalDevice) { mediaLibrary = new MediaLibrary(mediaSource); break; } } if (mediaLibrary == null) { return; } SongCollection songs = mediaLibrary.Songs; foreach (Song s in songs) { setlist.Add(s); } }
public static void Play(SongCollection s, Int32 i) { FrameworkDispatcher.Update(); MediaPlayer.Play(s, i); SongHelper.currentSong = s[i + 1]; }
public TrackListingViewModel(SongCollection songCollection, CurrentSongService currentSongService) { SongCollection = songCollection; this.currentSongService = currentSongService; Messenger.Default.Register<bool>(this, "IsLoading", OnLoadingChange); }
public void Add(string key, SongCollection value) { if (!SongList.ContainsKey(key) && !SongCollectionList.ContainsKey(key)) { SongCollectionList.Add(key, value); } }
public static void Play(SongCollection s) { FrameworkDispatcher.Update(); MediaPlayer.Play(s); SongHelper.currentSong = s[0]; }
private SongViewModel LookupSong(SongModel song) { if (song == null) { return(null); } if (SongLookupMap.ContainsKey(song.SongId)) { return(SongLookupMap[song.SongId]); } else { ArtistViewModel artist = LookupArtistById(song.ArtistId); AlbumViewModel album = LookupAlbumById(song.AlbumId); SongViewModel newSongViewModel = new SongViewModel(song, artist, album); SongLookupMap.Add(newSongViewModel.SongId, newSongViewModel); SongCollection.Add(newSongViewModel, newSongViewModel.SortName); FlatSongCollection.Add(newSongViewModel); if (LibraryLoaded) { NotifyPropertyChanged(Properties.IsEmpty); } return(newSongViewModel); } }
public TrackListingViewModel(SongCollection songCollection, CurrentSongService currentSongService) { SongCollection = songCollection; this.currentSongService = currentSongService; Messenger.Default.Register <bool>(this, "IsLoading", OnLoadingChange); }
TreeNode SongCollectionToTreeNodes(SongCollection songCollection) { var baseNode = new TreeNode(); baseNode.Text = songCollection.DisplayName; baseNode.Tag = songCollection; baseNode.ImageIndex = 0; baseNode.SelectedImageIndex = 0; foreach (var s in songCollection.Songs) { var node = new TreeNode(); node.Text = s.DisplayName; node.Tag = s; node.ImageIndex = 1; node.SelectedImageIndex = 1; int partNumber = 0; foreach (var p in s.Parts) { var partNode = new TreeNode(); partNode.Text = $"Part {partNumber}"; partNode.Tag = p; partNode.ImageIndex = 2; partNode.SelectedImageIndex = 2; node.Nodes.Add(partNode); partNumber++; } baseNode.Nodes.Add(node); } return(baseNode); }
public async Task GetSongByIdAsyncTest_ValidId_CorrectData() { // Arrange var songRepoMock = new Mock <ISongRepository>(); songRepoMock.Setup(mock => mock.GetSongByIdAsync(1)) .ReturnsAsync(new SongDataDto { Id = 1, Name = "Test", FileName = "test.mp3", Duration = 1337 }) .Verifiable(); var songCollection = new SongCollection(songRepoMock.Object, _dependencyMapper); // Act var song = await songCollection.GetSongByIdAsync(1); // Assert songRepoMock.Verify(); Assert.AreEqual(1, song.Id); Assert.AreEqual("Test", song.Name); Assert.AreEqual("test.mp3", song.FileName); Assert.AreEqual(1337, song.Duration); }
protected override void OnNavigatedTo(NavigationEventArgs e) { string select = null; string genre = null; if (this.NavigationContext.QueryString.ContainsKey("select")) { select = this.NavigationContext.QueryString["select"]; } if (this.NavigationContext.QueryString.ContainsKey("genre")) { genre = this.NavigationContext.QueryString["genre"]; } using (var library = new MediaLibrary()) { var songResults = from song in library.Songs where (song.Genre.ToString().ToLower().IndexOf(genre) == -1) select song; var playlists = library.Playlists; var playlist = library. var songResults = library.Songs.Where(s => s.Genre.ToString().ToLower().IndexOf(genre) > -1); foreach (var song in songResults) { songList.Add(song); } songCollection = library.Songs; } frameworkDispatchTimer.Start(); FrameworkDispatcher.Update(); }
public StatusViewModel(SongCollection songCollection) { this.songCollection = songCollection; songCollection.PropertyChanged += OnSongCollectionChange; if (ViewModelBase.IsInDesignModeStatic) Status = @"C:\SteamLibrary\SteamApps\common\Rocksmith2014"; }
public PlaylistPage() { InitializeComponent(); _SourceSongGrouped = new ObservableCollection<ArrSongGrouped>(); _Songs = _MediaLibrary.Songs; record2 = new Record2(this, 3); }
private void SongToList(SongCollection songs) { _songs = songs; var allSong = from Song song in songs select new ListSong(song.Artist.Name, song.Name, song.Album.Name); lstSongs.ItemsSource = allSong; }
public PlaylistPage() { InitializeComponent(); _SourceSongGrouped = new ObservableCollection<ArrSongGrouped>(); _Songs = _MediaLibrary.Songs; record = new Record(this); record.isAvailable = true; }
private Album(SongCollection songCollection, string name, Artist artist, Genre genre) { Songs = songCollection; Name = name; Artist = artist; Genre = genre; IsDisposed = false; }
public void CloseProject() { m_currentRom = null; m_primarySongCollection = null; this.projectTreeView.Nodes.Clear(); songPlayer.Shutdown(); }
public static SongCollection GetSongs() { using (SongHelper.library = new MediaLibrary()) { SongHelper.songs = library.Songs; SongHelper.playlists = library.Playlists; return songs; } }
public ListSongPage() { InitializeComponent(); source = new ObservableCollection<AddSong>(); songs = library.Songs; GroupSong(); GroupAlbum(); GroupArtist(); }
public SongCollectionViewModel() { Client = new BlobStorageClient( "ringify", "cFv/A0P1D8IRYgUsnO0poiYx8DzLVNFPuMrKFhaiTV24hhetdH2PF6oisr1dqUg1mWzQ08BasajNkUOg9NuM2g=="); SongList = new SongCollection(); SelectedSong = null; Client.BlobListUpdated += new BlobListUpdatedEventHandler(UpdateSongList); }
public static SongCollection GetSongs() { using (SongHelper.library = new MediaLibrary()) { SongHelper.songs = library.Songs; SongHelper.playlists = library.Playlists; return(songs); } }
protected Screen() { IsEnabled = true; IsVisible = true; Textures = new TextureCollection(); Camera = new Camera2D(); Songs = new SongCollection(); SoundEffects = new SoundEffectCollection(); }
public ListSongPage() { InitializeComponent(); _SourceSong = new ObservableCollection<ArrSong>(); _SourceArtist = new ObservableCollection<ArrSong>(); _Song = _MediaLibrary.Songs; GroupSong(); GroupAlbum(); GroupArtist(); }
public static void addCollection(List <Song> list, SongCollection songs) { if (songs != null) { for (int i = 0; i < songs.Count; i++) { list.Add(songs[i]); } } }
public void setSongs(SongCollection songCollection, TitleType title, string name) { songs = songCollection; Title = title; Title.Text = name; getItems(ListDirection.down); }
public StatusViewModel(SongCollection songCollection) { this.songCollection = songCollection; songCollection.PropertyChanged += OnSongCollectionChange; if (ViewModelBase.IsInDesignModeStatic) { Status = @"C:\SteamLibrary\SteamApps\common\Rocksmith2014"; } }
public MainWindow() { InitializeComponent(); Player.LoadedBehavior = MediaState.Manual; IQueueLoader ql = new FileQueueLoader(); SongCollection collection = new SongCollection(ql); _vm = new MainWindowViewModel(this, collection); DataContext = _vm; }
public MainWindowViewModel(IMusicPlayer m, SongCollection collection) { if (DesignerProperties.GetIsInDesignMode( new System.Windows.DependencyObject())) { return; } _seconds = 0; _playingSong = new Song(); QueueInfo = ""; _player = m; ElapsedTime = "00:00 / 00:00"; _incrementPlayingProgress = new Timer(); _incrementPlayingProgress.Interval = 1000; _currentQueue = collection; _incrementPlayingProgress.Elapsed += (sender, e) => { _seconds += 1000; PlayingProgress += 1000; string displayProgress = TimeSpan.FromMilliseconds(_seconds).ToString("mm\\:ss"); ElapsedTime = displayProgress + " / " + PlayingSong.DisplayDuration; }; _findSongEnd = new Timer(); _findSongEnd.Interval = 1; _findSongEnd.Elapsed += (sender, e) => { Application.Current.Dispatcher.Invoke(() => { if (_player.IsDone()) { Debug.WriteLine("Done"); if (++_playingIndex < _currentQueue.SongList.Count) { SelectedSong = _currentQueue.SongList[_playingIndex]; PlaySongAction(); } else { StopSongAction(); } } }); }; AddToQueueCommand = new CommandHandler(() => AddToQueueAction(), () => true); ClearQueueCommand = new CommandHandler(() => ClearQueueAction(), () => true); PlaySong = new CommandHandler(() => PlaySongAction(), () => true); PauseSong = new CommandHandler(() => PauseSongAction(), () => true); StopSong = new CommandHandler(() => StopSongAction(), () => true); FastForwardCommand = new CommandHandler(() => FastForwardAction(), () => true); RewindCommand = new CommandHandler(() => RewindAction(), () => true); }
public void AddToQueueCommand_Test() { IMusicPlayer mp = new MusicPlayerStub(); IQueueLoader ql = new QueueLoaderStub(); SongCollection collection = new SongCollection(ql); MainWindowViewModel vm = new MainWindowViewModel(mp, collection); vm.AddToQueueCommand.Execute(null); Assert.AreEqual(2, vm.SongList.Count); Assert.AreEqual("2 songs - 00:30", vm.QueueInfo); }
protected void SetUpdateCard() { int currentSongID = int.Parse(ddlSongs.SelectedValue); _songDAL = new SongDAL(); SongCollection song = _songDAL.GetSong(currentSongID); ddlUpdateArtist.SelectedValue = song.ArtistID.ToString(); txtUpdateTitle.Text = song.Title; txtUpdatePrice.Text = song.Price.ToString(); }
public void SetRom(Rom currentRom) { m_currentRom = currentRom; m_primarySongCollection = currentRom.OverworldSongs; // new SongCollection(); //m_primarySongCollection.LoadFromNspc(m_currentRom.BaseNSPC); //m_primarySongCollection.FixDurations(); //m_primarySongCollection.DisplayName = "Startup"; LoadProjectTree(); }
private void Instance_PartyStateUpdated(object sender, PartyStatus e) { if (e != null) { CurrentItem = SongCollection.ElementAt(e.TrackIndex); CurrentItemIndex = e.TrackIndex; Duration = e.Duration; Position = e.Progress; PlayerState = e.State; } }
public ListSongPage() { InitializeComponent(); _SourceSong = new ObservableCollection<ArrSong>(); _SourceArtist = new ObservableCollection<ArrSong>(); _Song = _MediaLibrary.Songs; GroupSong(); GroupAlbum(); GroupArtist(); record = new Record(this); record.isAvailable = true; }
private void loadSongs() { mySongs = new SongCollection(); mySongs.Add(new Song("Eric Clapton", "After Midnight", 338)); mySongs.Add(new Song("Sister Hazel", "All for You", 392)); mySongs.Add(new Song("Josh Groban", "America (Live Album Version)", 249)); mySongs.Add(new Song("The Surfaris", "Apache", 171)); mySongs.Add(new Song("Sister Hazel", "Beautiful Thing", 280)); mySongs.Add(new Song("Jesse McCartney", "Because You Live", 223)); mySongs.Add(new Song("The Ramones", "Blitzkreig Bop", 97)); mySongs.Add(new Song("Eric Clapton", "Blues Power", 440)); mySongs.Add(new Song("The Police", "Bring On the Night", 316)); mySongs.Add(new Song("Sister Hazel", "Champagne High", 306)); mySongs.Add(new Song("Sister Hazel", "Change Your Mind", 312)); mySongs.Add(new Song("Black Sabbath", "Children of the Grave", 326)); mySongs.Add(new Song("Black Sabbath", "Children of the Sea", 369)); mySongs.Add(new Song("Eric Clapton", "Cocaine", 459)); mySongs.Add(new Song("Zero 7", "Destiny", 224)); mySongs.Add(new Song("Eric Clapton", "Double Trouble", 492)); mySongs.Add(new Song("Neil Finn & Johnny Marr", "Down on the Corner", 271)); mySongs.Add(new Song("Dokken", "Dream Warriors", 254)); mySongs.Add(new Song("Eric Clapton", "Early In the Morning", 431)); mySongs.Add(new Song("Santana", "Esperando", 357)); mySongs.Add(new Song("Coldplay", "Fix You", 277)); mySongs.Add(new Song("Black Sabbath", "Fluff", 60)); mySongs.Add(new Song("Foghat", "Fool for the City", 331)); mySongs.Add(new Song("Eisley", "Golly Sandra (Live Version)", 218)); mySongs.Add(new Song("The Veronicas", "Heavily Broken (Live Version)", 259)); mySongs.Add(new Song("Zero 7", "Home", 383)); mySongs.Add(new Song("Neil Finn & Eddie Vedder", "I See Red", 211)); mySongs.Add(new Song("John Denver", "I Want to Live", 226)); mySongs.Add(new Song("Black Sabbath", "Iron Man", 450)); mySongs.Add(new Song("The Police", "King of Pain", 353)); mySongs.Add(new Song("Eric Clapton", "Lay Down Sally", 335)); mySongs.Add(new Song("Kenny Wayne Shepherd", "Live On", 275)); mySongs.Add(new Song("Michael W. Smith", "Live the Life", 275)); mySongs.Add(new Song("Big & Rich", "Live This Life (Music Only)", 262)); mySongs.Add(new Song("Kenny Chesney", "Live Those Songs", 248)); mySongs.Add(new Song("Belle and Sebastian", "Mayfly (Live Version)", 228)); mySongs.Add(new Song("The Police", "Message in a Bottle", 276)); mySongs.Add(new Song("Zero 7", "Morning Song", 426)); mySongs.Add(new Song("Dokken", "Mr. Scary", 503)); mySongs.Add(new Song("Madonna", "Music", 151)); mySongs.Add(new Song("Black Sabbath", "N.I.B.", 309)); mySongs.Add(new Song("Black Sabbath", "Neon Knights", 276)); mySongs.Add(new Song("Goldfrapp", "Number 1", 244)); mySongs.Add(new Song("Josh Groban", "Oceano (Live Album Version)", 232)); mySongs.Add(new Song("The Ramones", "Pet Sematary", 220)); mySongs.Add(new Song("The Surfaris", "Pipeline", 123)); mySongs.Add(new Song("Sarah McLachlan", "Push", 244)); }
/// <summary> /// Add the specified Song to the local collections and persistent storage /// </summary> /// <param name="songToAdd"></param> public static async void AddSongAsync(Song songToAdd) { // Must wait for this to get the song id await DbAccess.InsertAsync(songToAdd); lock ( lockObject ) { SongCollection.Add(songToAdd); IdLookup.Add(songToAdd.Id, songToAdd); artistAlbumLookup.AddValue(songToAdd.ArtistAlbumId, songToAdd); albumLookup.AddValue(songToAdd.AlbumId, songToAdd); } }
private void Configuration_ConfigChanged(object sender, ConfigEventArgs e) { if (e.Config != ConfigEventArgs.Configs.LibraryPath) { return; } SongCollector.Stop(); ArtistCollection.GetMainCollection().Clear(); AlbumCollection.GetMainCollection().Clear(); SongCollection.GetMainCollection().Clear(); SongCollector.Start(); }
void MainPage_Loaded(object sender, RoutedEventArgs e) { // Load Music Library FrameworkDispatcher.Update(); MediaLibrary library = new MediaLibrary(); songCollection = library.Songs; MediaPlayer.ActiveSongChanged += new EventHandler <EventArgs>(MediaPlayer_ActiveSongChanged); MediaPlayer.MediaStateChanged += new EventHandler <EventArgs>(MediaPlayer_MediaStateChanged); UpdateCurrentSongInformation(); }
public Form1() { InitializeComponent(); songlist.Source = SongCollection.GetMainCollection(); albumGrid.Source = AlbumCollection.GetMainCollection(); artistGrid.Source = ArtistCollection.GetMainCollection(); Configuration.ConfigChanged += Configuration_ConfigChanged; InitSearch(); Playlist.InitPlaylist(); //Fetch all the songs SongCollector.Start(); }
public MusicOffline() { Offline_Album = new ObservableCollection <MyAlbum>(); Update_LibraryAlbums(); Offline_Artist = new ObservableCollection <MyArtist>(); Update_LibraryArtists(); offL_Current_Songs = new ObservableCollection <MySong>(); Update_LibrarySongs(); MediaLibrary ML = new MediaLibrary(); List_Current_Song = ML.Songs; }
/// <summary> /// Delete a single song from local and peristanet storage /// </summary> /// <param name="songToDelete"></param> public static void DeleteSong(Song songToDelete) { lock ( lockObject ) { if (IdLookup.ContainsKey(songToDelete.Id) == true) { SongCollection.Remove(songToDelete); IdLookup.Remove(songToDelete.Id); artistAlbumLookup[songToDelete.ArtistAlbumId].Remove(songToDelete); albumLookup[songToDelete.AlbumId].Remove(songToDelete); } } DbAccess.DeleteAsync(songToDelete); }
public SongCollection GetSongs() { IWMPMediaCollection media = wmp.mediaCollection; IWMPPlaylist playlist = media.getAll(); List<Song> songlist = new List<Song>(); for (int i = 0; i < playlist.count; i++) { IWMPMedia temp = playlist[i]; if (temp.getItemInfo("MediaType") == "audio") { int wmprating; int rating; int tracknumber; int playcount; bool IsProtected; if (!int.TryParse(temp.getItemInfo("UserRating"), out wmprating)) { throw new Exception(); } if (wmprating >= 87) rating = 10; else if (wmprating >= 63) rating = 8; else if (wmprating >= 38) rating = 6; else if (wmprating >= 13) rating = 4; else if (wmprating >= 1) rating = 2; else rating = 0; if (!int.TryParse(temp.getItemInfo("WM/TrackNumber"), out tracknumber)) { tracknumber = 0; } if (!int.TryParse(temp.getItemInfo("PlayCount"), out playcount)) { throw new Exception(); } if (!bool.TryParse(temp.getItemInfo("Is_Protected"), out IsProtected)) { throw new Exception(); } TimeSpan duration = new TimeSpan(0, 0, 0, 0, (int)(temp.duration * 1000.0)); songlist.Add(new Song(temp.name, duration, rating, tracknumber, temp, mediasource)); } } SongCollection songs = new SongCollection(songlist); return songs; }
public Gamestate(ContentManager content, bool transparent, string bgMusicFolder = null) { Transparent = transparent; _content = content; if (!String.IsNullOrEmpty(bgMusicFolder)) { BgMusic = new SongCollection(); string folder = "Content/" + c_bgMusicDir + bgMusicFolder + "/"; foreach (string filename in Directory.GetFiles(folder)) { string name = filename.Remove(0, "Content/".Length); BgMusic.Add(Content.Load<Song>(name)); } } if (BgMusic != null) { MediaPlayer.Play(BgMusic, s_rand.Next(BgMusic.Count)); } }
// You might be tempted to put this method into the SongCollection class. After all, // the logic pertains to the song collection as a whole. However, it performs user // interface code (outputs to the screen) and in general, we try to separate UI code // from business code. We'll get into this more later in the course. private static void displaySongs(SongCollection songs) { if (songs.Count > 0) { Console.WriteLine("{0, -35} {1, -30} {2, 8}", "Title", "Artist", "Length"); Console.WriteLine(new string('=', 75)); foreach (Song song in songs) { Console.WriteLine("{0, -35} {1, -30} {2, 8}" , song.Title , song.Artist , song.Length); } Console.WriteLine(new string('-', 75)); } else { Console.WriteLine("Nothing to Display\n\n"); } }
public MainViewModel(IDialogService dialogService, IErrorService errorService, SongCollection songCollection) { _dialogService = dialogService; _errorService = errorService; this.songCollection = songCollection; songLoader = new SongLoader(_dialogService, songCollection); // Re-raise events for the view songCollection.PropertyChanged += (sender, args) => this.RaisePropertyChanged(args.PropertyName); songLoader.PropertyChanged += (sender, args) => this.RaisePropertyChanged(args.PropertyName); songLoader.PropertyChanged += OnIsLoadingToggled; OpenFileCommand = new RelayCommand(songLoader.OpenFile); LoadDiskTracksCommand = new RelayCommand(songLoader.LoadDiskTracks); LoadDLCTracksCommand = new RelayCommand(songLoader.LoadDLCTracks); SelectedGuitarPath = RockSmithTabExplorer.Properties.Settings.Default.GuitarPath; if (ViewModelBase.IsInDesignModeStatic) TrackToolBarVisible = true; }
private void PlatformLoad(Action<int> progressCallback) { List<Song> songList = new List<Song>(); List<Album> albumList = new List<Album>(); using (var musicCursor = Context.ContentResolver.Query(MediaStore.Audio.Media.ExternalContentUri, null, null, null, null)) { if (musicCursor != null) { Dictionary<string, Artist> artists = new Dictionary<string, Artist>(); Dictionary<string, Album> albums = new Dictionary<string, Album>(); Dictionary<string, Genre> genres = new Dictionary<string, Genre>(); // Note: Grabbing album art using MediaStore.Audio.AlbumColumns.AlbumArt and // MediaStore.Audio.AudioColumns.AlbumArt is broken // See: https://code.google.com/p/android/issues/detail?id=1630 // Workaround: http://stackoverflow.com/questions/1954434/cover-art-on-android int albumNameColumn = musicCursor.GetColumnIndex(MediaStore.Audio.AlbumColumns.Album); int albumArtistColumn = musicCursor.GetColumnIndex(MediaStore.Audio.AlbumColumns.Artist); int albumIdColumn = musicCursor.GetColumnIndex(MediaStore.Audio.AlbumColumns.AlbumId); int genreColumn = musicCursor.GetColumnIndex(MediaStore.Audio.GenresColumns.Name); // Also broken :( int artistColumn = musicCursor.GetColumnIndex(MediaStore.Audio.AudioColumns.Artist); int titleColumn = musicCursor.GetColumnIndex(MediaStore.Audio.AudioColumns.Title); int durationColumn = musicCursor.GetColumnIndex(MediaStore.Audio.AudioColumns.Duration); int assetIdColumn = musicCursor.GetColumnIndex(MediaStore.Audio.AudioColumns.Id); if (titleColumn == -1 || durationColumn == -1 || assetIdColumn == -1) { Debug.WriteLine("Missing essential properties from music library. Returning empty library."); albumCollection = new AlbumCollection(albumList); songCollection = new SongCollection(songList); return; } for (musicCursor.MoveToFirst(); !musicCursor.IsAfterLast; musicCursor.MoveToNext()) try { long durationProperty = musicCursor.GetLong(durationColumn); TimeSpan duration = TimeSpan.FromMilliseconds(durationProperty); // Exclude sound effects if (duration < MinimumSongDuration) continue; string albumNameProperty = (albumNameColumn > -1 ? musicCursor.GetString(albumNameColumn) : null) ?? "Unknown Album"; string albumArtistProperty = (albumArtistColumn > -1 ? musicCursor.GetString(albumArtistColumn) : null) ?? "Unknown Artist"; string genreProperty = (genreColumn > -1 ? musicCursor.GetString(genreColumn) : null) ?? "Unknown Genre"; string artistProperty = (artistColumn > -1 ? musicCursor.GetString(artistColumn) : null) ?? "Unknown Artist"; string titleProperty = musicCursor.GetString(titleColumn); long assetId = musicCursor.GetLong(assetIdColumn); var assetUri = ContentUris.WithAppendedId(MediaStore.Audio.Media.ExternalContentUri, assetId); long albumId = albumIdColumn > -1 ? musicCursor.GetInt(albumIdColumn) : -1; var albumArtUri = albumId > -1 ? ContentUris.WithAppendedId(Uri.Parse("content://media/external/audio/albumart"), albumId) : null; Artist artist; if (!artists.TryGetValue(artistProperty, out artist)) { artist = new Artist(artistProperty); artists.Add(artist.Name, artist); } Artist albumArtist; if (!artists.TryGetValue(albumArtistProperty, out albumArtist)) { albumArtist = new Artist(albumArtistProperty); artists.Add(albumArtist.Name, albumArtist); } Genre genre; if (!genres.TryGetValue(genreProperty, out genre)) { genre = new Genre(genreProperty); genres.Add(genre.Name, genre); } Album album; if (!albums.TryGetValue(albumNameProperty, out album)) { album = new Album(new SongCollection(), albumNameProperty, albumArtist, genre, albumArtUri); albums.Add(album.Name, album); albumList.Add(album); } var song = new Song(album, artist, genre, titleProperty, duration, assetUri); song.Album.Songs.Add(song); songList.Add(song); } catch (Exception e) { Debug.WriteLine("MediaLibrary exception: " + e.Message); } } musicCursor.Close(); } albumCollection = new AlbumCollection(albumList); songCollection = new SongCollection(songList); }
public static void Play(SongCollection songs, int index) { throw new NotImplementedException(); }
public static void Play(SongCollection songs, int index) { Queue.Clear(); numSongsInQueuePlayed = 0; foreach (Song song in songs) { Queue.Add(song); } Queue.ActiveSongIndex = index; PlaySong(Queue.ActiveSong); }
public static void Play(SongCollection songs) { Play(songs, 0); }
private void PlatformLoad(Action<int> progressCallback) { #if !WINDOWS_UAP Task.Run(async () => { if (musicFolder == null) { try { musicFolder = KnownFolders.MusicLibrary; } catch (Exception e) { Debug.WriteLine("Failed to access Music Library: " + e.Message); albumCollection = new AlbumCollection(new List<Album>()); songCollection = new SongCollection(new List<Song>()); return; } } var files = new List<StorageFile>(); await this.GetAllFiles(musicFolder, files); var songList = new List<Song>(); var albumList = new List<Album>(); var artists = new Dictionary<string, Artist>(); var albums = new Dictionary<string, Album>(); var genres = new Dictionary<string, Genre>(); var cache = new Dictionary<string, MusicProperties>(); // Read cache var cacheFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(CacheFile, CreationCollisionOption.OpenIfExists); using (var stream = new BinaryReader(await cacheFile.OpenStreamForReadAsync())) try { for (; stream.BaseStream.Position < stream.BaseStream.Length; ) { var entry = MusicProperties.Deserialize(stream); cache.Add(entry.Path, entry); } } catch { } // Write cache cacheFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(CacheFile, CreationCollisionOption.ReplaceExisting); using (var stream = new BinaryWriter(await cacheFile.OpenStreamForWriteAsync())) { int prevProgress = 0; for (int i = 0; i < files.Count; i++) { var file = files[i]; try { MusicProperties properties; if (!(cache.TryGetValue(file.Path, out properties) && properties.TryMatch(file))) properties = new MusicProperties(file); properties.Serialize(stream); if (string.IsNullOrWhiteSpace(properties.Title)) continue; Artist artist; if (!artists.TryGetValue(properties.Artist, out artist)) { artist = new Artist(properties.Artist); artists.Add(artist.Name, artist); } Artist albumArtist; if (!artists.TryGetValue(properties.AlbumArtist, out albumArtist)) { albumArtist = new Artist(properties.AlbumArtist); artists.Add(albumArtist.Name, albumArtist); } Genre genre; if (!genres.TryGetValue(properties.Genre, out genre)) { genre = new Genre(properties.Genre); genres.Add(genre.Name, genre); } Album album; if (!albums.TryGetValue(properties.Album, out album)) { var thumbnail = Task.Run(async () => await properties.File.GetThumbnailAsync(ThumbnailMode.MusicView, 300, ThumbnailOptions.ResizeThumbnail)).Result; album = new Album(new SongCollection(), properties.Album, albumArtist, genre, thumbnail.Type == ThumbnailType.Image ? thumbnail : null); albums.Add(album.Name, album); albumList.Add(album); } var song = new Song(album, artist, genre, properties); song.Album.Songs.Add(song); songList.Add(song); } catch (Exception e) { Debug.WriteLine("MediaLibrary exception: " + e.Message); } int progress = 100 * i / files.Count; if (progress > prevProgress) { prevProgress = progress; if (progressCallback != null) progressCallback.Invoke(progress); } } } if (progressCallback != null) progressCallback.Invoke(100); albumCollection = new AlbumCollection(albumList); songCollection = new SongCollection(songList); }).Wait(); #endif }
public PlaylistPage() { InitializeComponent(); source = new ObservableCollection<AddSong1>(); songs = library.Songs; }
public static void Play(SongCollection collection, int index = 0) { _queue.Clear(); _numSongsInQueuePlayed = 0; foreach(var song in collection) _queue.Add(song); _queue.ActiveSongIndex = index; PlaySong(_queue.ActiveSong); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); font = Game.Content.Load<SpriteFont>("song_selection"); boxCell = Game.Content.Load<Texture2D>("blank"); nameWidth = (int)(0.5f * size.X); artistWidth = (int)(0.2f * size.X); albumWidth = (int)(0.2f * size.X); durationWidth = (int)(0.1f * size.X); numEntries = (int)(size.Y / font.LineSpacing) - 2; if (MediaSource.GetAvailableMediaSources().Count > 0) { mediaSourceName = MediaSource.GetAvailableMediaSources()[0].Name; library = new MediaLibrary(MediaSource.GetAvailableMediaSources()[0]).Songs; if (library.Count > 0) { MediaPlayer.Play(library[selected]); NarlyGame.currentSong = library[selected].Name; } } initializeSongDataArray(); base.LoadContent(); }
public void HandleInput(InputState input) { int oldSelected = selected; int oldLibrary = libraryIndex; if (input.IsMenuDown(screen.ControllingPlayer)) { if (selected < library.Count - 1) { ++selected; if (selected == numEntries + index) { ++index; } loadAroundIndex(selected); } } if (input.IsMenuUp(screen.ControllingPlayer)) { if (selected > 0) { --selected; if (selected == index - 1) { --index; } loadAroundIndex(selected); } } PlayerIndex player; if (input.IsNewButtonPress(Buttons.X, screen.ControllingPlayer, out player)) { MediaPlayer.Play(library[selected]); } if (input.IsNewButtonPress(Buttons.LeftShoulder, screen.ControllingPlayer, out player) || input.IsNewKeyPress(Keys.Left, screen.ControllingPlayer, out player)) { if (libraryIndex > 0) { --libraryIndex; mediaSourceName = MediaSource.GetAvailableMediaSources()[libraryIndex].Name; library = new MediaLibrary(MediaSource.GetAvailableMediaSources()[libraryIndex]).Songs; index = 0; selected = 0; initializeSongDataArray(); } } if (input.IsNewButtonPress(Buttons.RightShoulder, screen.ControllingPlayer, out player) || input.IsNewKeyPress(Keys.Right, screen.ControllingPlayer, out player)) { if (libraryIndex < MediaSource.GetAvailableMediaSources().Count - 1) { ++libraryIndex; mediaSourceName = MediaSource.GetAvailableMediaSources()[libraryIndex].Name; library = new MediaLibrary(MediaSource.GetAvailableMediaSources()[libraryIndex]).Songs; index = 0; selected = 0; initializeSongDataArray(); } } if (input.IsNewButtonPress(Buttons.RightTrigger, screen.ControllingPlayer, out player)) { if (library.Count > 0) { char c = '0'; // Skip ahead artist letter if (SongDataArray[selected].Artist.Length > 0) { c = SongDataArray[selected].Artist.ToLower()[0]; } int newIndex; for (newIndex = selected; newIndex < library.Count; ++newIndex) { loadAroundIndex(newIndex); if (SongDataArray[newIndex].Artist.Length == 0) continue; if (SongDataArray[newIndex].Artist.ToLower()[0] != c) break; } selected = Math.Min(newIndex, library.Count - 1); index = selected; } } if (input.IsNewButtonPress(Buttons.LeftTrigger, screen.ControllingPlayer, out player)) { if (library.Count > 0) { char c = 'z'; // Skip back artist letter if (SongDataArray[selected].Artist.Length > 0) { c = SongDataArray[selected].Artist.ToLower()[0]; } int newIndex; bool nextLetter = false; for (newIndex = selected; newIndex >= 0; --newIndex) { loadAroundIndex(newIndex); if (SongDataArray[newIndex].Artist.Length == 0) continue; if (SongDataArray[newIndex].Artist.ToLower()[0] != c && nextLetter) { newIndex++; break; } if (SongDataArray[newIndex].Artist.ToLower()[0] != c) { c = SongDataArray[newIndex].Artist.ToLower()[0]; nextLetter = true; } } selected = Math.Max(newIndex, 0); index = selected; } } if (oldSelected != selected || libraryIndex != oldLibrary) { if (library.Count > selected) { MediaPlayer.Play(library[selected]); NarlyGame.currentSong = library[selected].Name; } } }
public static void Play(SongCollection collection, int index = 0) { MediaPlayer._queue.Clear(); MediaPlayer._numSongsInQueuePlayed = 0; foreach (Song song in collection) MediaPlayer._queue.Add(song); MediaPlayer._queue.ActiveSongIndex = index; MediaPlayer.PlaySong(MediaPlayer._queue.ActiveSong); }