Example #1
0
        /// <summary>
        /// Get album name, art and add to list.
        /// </summary>
        /// <param></param>
        /// <returns></returns>
        private Album GetAlbumInfo()
        {
            Album newAlbum = new Album();
            newAlbum.Artist = this.Artist;
            if (!tag.IsEmpty)
            {
                if (tag.Album != null)
                {
                    newAlbum.AlbumName = tag.Album;
                }
                else
                {
                    newAlbum.AlbumName = "Unknown";
                }

                newAlbum.AlbumArt = tag.Pictures;
            }
            else
            {
                // in the rare chance taglibs doesnt recognise tags, try reading tags via cscore
                if (cTag.QuickInfo.Album != "")
                {
                    newAlbum.AlbumName = cTag.QuickInfo.Album;
                }
                else
                    newAlbum.AlbumName = "Unknown";

                // set album art - converts from image to ipicture
                newAlbum.AlbumArt = new IPicture[]
                {
                    new Picture(new ByteVector((byte[])new System.Drawing.ImageConverter().ConvertTo(cTag.QuickInfo.Image, typeof(byte[]))))
                };
            }
            return newAlbum;
        }
Example #2
0
        public static MusicCollection GetSongs(this Client client)
        {
            IXPFile request = new IXPFile();
            request.NetworkFunction = "com.projectgame.music.music.getsongs";
            IXPFile response = client.IXPRequest(request);

            MusicCollection musicCollection = new MusicCollection();
            int artistCount = int.Parse(response.GetInfoValue("artist_count"));

            for(int currentArtistIndex = 0; currentArtistIndex < artistCount; currentArtistIndex++) {
                int artistID = int.Parse(response.GetInfoValue("artist_" + currentArtistIndex + "_id"));
                string artistName = response.GetInfoValue("artist_" + currentArtistIndex + "_name");
                Artist artist = new Artist(artistID, artistName);
                musicCollection.Artists.Add(artist);

                int albumCount = int.Parse(response.GetInfoValue("artist_" + currentArtistIndex + "_album_count"));

                for(int currentAlbumIndex = 0; currentAlbumIndex < albumCount; currentAlbumIndex++) {
                    int albumID = int.Parse(response.GetInfoValue("artist_" + currentArtistIndex + "_album_" + currentAlbumIndex + "_id"));
                    string albumName = response.GetInfoValue("artist_" + currentArtistIndex + "_album_" + currentAlbumIndex + "_name");
                    Album album = new Album(albumID, albumName);
                    artist.Albums.Add(album);

                    int songCount = int.Parse(response.GetInfoValue("artist_" + currentArtistIndex + "_album_" + currentAlbumIndex + "_song_count"));

                    for(int currentSongIndex = 0; currentSongIndex  < songCount; currentSongIndex++) {
                        int songID = int.Parse(response.GetInfoValue("artist_" + currentArtistIndex + "_album_" + currentAlbumIndex + "_song_" + currentSongIndex + "_id"));
                        string songName = response.GetInfoValue("artist_" + currentArtistIndex + "_album_" + currentAlbumIndex + "_song_" + currentSongIndex + "_name");
                        Song song = new Song(songID, songName);
                        album.Songs.Add(song);
                    }
                }
            }

            return musicCollection;
        }
Example #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Album);
            // Create your application here

            var startPause      = FindViewById <Button>(Resource.Id.startpause);
            var nextSong        = FindViewById <Button>(Resource.Id.nextSong);
            var previousSong    = FindViewById <Button>(Resource.Id.previousSong);
            var songProgressBar = FindViewById <SeekBar>(Resource.Id.songProgressBar);

            startPause.Click += delegate
            {
                if (Player.IsPlaying)
                {
                    Player.Pause();
                }
                else
                {
                    Player.Start();
                }
            };
            nextSong.Click += delegate
            {
                NextSong(songProgressBar);
            };
            previousSong.Click += delegate
            {
                var nextSongIndex = _album.Songs.IndexOf(_currentSong) - 1;

                if (nextSongIndex < 0)
                {
                    Player.Reset();
                    _currentSong = null;
                }
                else
                {
                    _currentSong = _album.Songs[nextSongIndex];
                    Player.Reset();
                    var uri = Uri.Parse(_currentSong.SongPath);
                    Player.SetAudioStreamType(Stream.Music);
                    Player.SetDataSource(ApplicationContext, uri);
                    Player.Prepare();
                    Player.Start();
                    songProgressBar.Max      = Player.Duration;
                    songProgressBar.Progress = 0;
                }
            };


            Title = Intent.GetStringExtra("AlbumName") ?? "";
            if (Title != "")
            {
                _album = ApplicationData.Albums.SingleOrDefault(a => a.Name == Title);
            }

            if (_album == null)
            {
                return;
            }

            var layout = FindViewById <LinearLayout>(Resource.Id.linearSongsLayout);

            for (int i = 0; i < _album.Songs.Count; i++)
            {
                var button = new Button(this)
                {
                    Text = $"{i+1} {_album.Songs[i].Title}",
                    Id   = i
                };
                button.Click += (sender, args) =>
                {
                    _currentSong = _album.Songs[button.Id];

                    if (_currentSong != null)
                    {
                        Player.Reset();
                        var uri = Uri.Parse(_currentSong.SongPath);
                        Player.SetAudioStreamType(Stream.Music);
                        Player.SetDataSource(ApplicationContext, uri);
                        Player.Prepare();
                        Player.Start();
                        songProgressBar.Max      = Player.Duration;
                        songProgressBar.Progress = 0;
                    }
                };

                layout.AddView(button);
            }


            var progressText = FindViewById <TextView>(Resource.Id.progressText);

            songProgressBar.StopTrackingTouch += delegate
            {
                progressText.Text = $"{songProgressBar.Progress}";
                Player.SeekTo(songProgressBar.Progress);
            };

            SetCountDown();

            Player.Completion += delegate
            {
                NextSong(songProgressBar);
            };
        }
Example #4
0
        public static (List <Song>, int, int, int) GetSongsData()
        {
            var minDuration   = 1000;
            var maxDuration   = 0;
            var totalDuration = 0;

            var artist = new Artist();

            artist.Name = "Powerwolf";
            Console.WriteLine(artist.Name);
            Console.WriteLine(Artist.Genre.Techno);

            var artist2 = new Artist("Lordi");

            Console.WriteLine(artist2.Name);
            Console.WriteLine(Artist.Genre.DubStep);

            var artist3 = new Artist("Sabaton");

            Console.WriteLine(artist3.Name);
            Console.WriteLine(Artist.Genre.Classic);

            var album = new Album();

            album.Name = "New Album";
            album.Year = 2018;

            List <Song> songs  = new List <Song>();
            var         random = new Random();

            for (int i = 0; i < 10; i++)
            {
                var song = new Song()
                {
                    Duration = random.Next(1000),
                    Name     = $"New song {i}",
                    Album    = album,
                    Artist   = artist
                };

                songs.Add(song);

                totalDuration += songs[i].Duration;
                if (songs[i].Duration < minDuration)
                {
                    minDuration = song.Duration;
                }

                maxDuration = Math.Max(maxDuration, song.Duration);
            }


            //return new Object[]{ songs , totalDuration, maxDuration, minDuration };

            //return new Tuple<Song[], int, int, int>(songs, totalDuration, maxDuration, minDuration);

            return(songs, totalDuration, maxDuration, minDuration);


            //class Tuplesongsarrayintintint {
            //Song[] Item1;
            //int Item2
            //}
        }