Exemplo n.º 1
0
 // gets a song with its id
 public Song getSong(int ID)
 {
     return(MediaDatabase.getSong(ID));
 }
Exemplo n.º 2
0
 // gets all songs for selected artist
 public List <Song> getSongsByArtist(string artist)
 {
     return(MediaDatabase.getSongsByArtist(artist));
 }
Exemplo n.º 3
0
 // gets all songs by artist in a particular album
 public List <Song> getSongsByArtistAndAlbum(string artist, string album)
 {
     return(MediaDatabase.getSongsByArtistAndAlbum(artist, album));
 }
Exemplo n.º 4
0
 // gets all albums for selected artist
 public List <string> getAllAlbumsForArtist(string artist)
 {
     return(MediaDatabase.getAlbumsByArtist(artist));
 }
Exemplo n.º 5
0
 // updates database
 public Boolean updateDatabase()
 {
     return(MediaDatabase.updateDatabase());
 }
Exemplo n.º 6
0
 // gets all artists in database
 public List <string> getAllArtists()
 {
     return(MediaDatabase.getArtists());
 }
Exemplo n.º 7
0
 // gets all songs in database
 public List <Song> getAllSongs()
 {
     return(MediaDatabase.getSongs());
 }
Exemplo n.º 8
0
 // gets all albums in database
 public List <string> getAllAlbums()
 {
     return(MediaDatabase.getAlbums());
 }
Exemplo n.º 9
0
 // gets songs in selected album
 public List <Song> getSongsByAlbum(string album)
 {
     return(MediaDatabase.getSongsByAlbum(album));
 }
Exemplo n.º 10
0
        public static Boolean updateDatabase()
        {
            /* if the path has been changed and the database
            * exists drop all database data in Song table */
            if (Properties.Settings.Default.oldDatabasePath != Properties.Settings.Default.databasePath)
            {
                if (MediaDatabase.checkExistance() == true)
                {
                    using (var conn = new SQLite.SQLiteConnection(loadConnectionString()))
                    {
                        string query = "DROP TABLE Song";
                        conn.ExecuteScalar <string>(query);
                    }
                }
            }



            // if database doesn't exist create
            if (MediaDatabase.checkExistance() != true)
            {
                // in sqlite-net-pcl creating a table will create the database if it doesn't exist
                createTable();
            }


            string[] artists;

            // if we cannot get directories, access to one has been denied. IE the update failed
            try
            {
                artists = Directory.GetDirectories(Properties.Settings.Default.databasePath);
            }
            catch
            {
                return(false);
            }


            // for each artist found get their albums
            foreach (string oneArtist in artists)
            {
                string[] albums;
                // if access to a album directory is denied, the update was unsuccessful
                try
                {
                    albums = Directory.GetDirectories(oneArtist);
                }
                catch
                {
                    return(false);
                }
                // for each album find the songs
                foreach (string oneAlbum in albums)
                {
                    DirectoryInfo dir = new DirectoryInfo(oneAlbum);

                    // If access to a song in an album directory is denied, the update was unsuccessful
                    try
                    {
                        Directory.GetFiles(oneAlbum);
                    }
                    catch
                    {
                        return(false);
                    }

                    // going through individual files in album directory and adding them to a database
                    foreach (FileInfo flinfo in dir.GetFiles())
                    {
                        string name = flinfo.Name;
                        // ensuring the file is a .mp3 or .wav
                        if (name.Contains(".mp3") || name.Contains(".wav"))
                        {
                            string pathAndName = oneAlbum + "\\" + name;
                            // if the song isn't in the database, add it.
                            // if it is, do nothing.
                            if (!checkIfSongIsInDatabase(pathAndName))
                            {
                                var      tfile    = TagLib.File.Create(@pathAndName);
                                string   title    = tfile.Tag.Title;
                                string   album    = tfile.Tag.Album;
                                string   artist   = tfile.Tag.FirstAlbumArtist;
                                TimeSpan duration = tfile.Properties.Duration;

                                Song song = new Song(name, artist, title, album, duration, pathAndName);
                                insertMp3(song);
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }



            return(true);
        }