Esempio n. 1
0
 public Status SetSource(Song playedSong)
 {
     if (playedSong.Downloaded)
     {
         _stream = Bass.BASS_StreamCreateFile(playedSong.DownloadedUri.LocalPath, 0, 0, BASSFlag.BASS_DEFAULT);
     }
     else
     {
         _stream = Bass.BASS_StreamCreateURL(playedSong.Uri.ToString(), 0, 0, null, new IntPtr(0));
     }
     if (_stream != 0)
     {
         return Status.OK;
     }
     else
     {
         if (playedSong.Downloaded)
         {
             playedSong.Downloaded = false;
             _stream = Bass.BASS_StreamCreateURL(playedSong.Uri.ToString(), 0, 0, null, new IntPtr(0));
         }
         if (_stream != 0)
         {
             return Status.OK;
         }
         else
         {
             return Status.Error;
         }
     }
 }
Esempio n. 2
0
        public Song[] GetAudioExternal(string userID, string token)
        {
            string GetAudioRequest = String.Format("https://api.vk.com/method/audio.get?owner_id={0}&access_token={1}", userID, token);
            WebRequest AudioRequest = WebRequest.Create(GetAudioRequest);
            WebResponse AudioAnswer = AudioRequest.GetResponse();
            Stream dataStream = AudioAnswer.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string responeFromServer = reader.ReadToEnd();

            reader.Close();
            dataStream.Close();
            responeFromServer = HttpUtility.HtmlDecode(responeFromServer);

            JObject obj = JObject.Parse(responeFromServer);
            Song[] Songs;
            try
            {
                Songs = obj["response"].Children().Skip(1).Select(c => c.ToObject<Song>()).ToArray();
            }
            catch (NullReferenceException)
            {
                Songs = new Song[0];
            }
            return Songs;
        }
 public void AddToList_IDOfFirstSongInArrayAndFifthSongInListShouldBeTheSame()
 {
     Playlist.Playlist playlist = new Playlist.Playlist();
     List<Song> songList = new List<Song>();
     songList.AddRange(new Song[] { new Song(1), new Song(2), new Song(3), new Song(4) });
     playlist.UpdateList(new ObservableCollection<Song>(songList));
     Song[] insertedArrayOfSongs = new Song[] { new Song(9), new Song(8), new Song(7) };
     playlist.AddToList(insertedArrayOfSongs, 4);
     Assert.AreEqual(insertedArrayOfSongs[0].ID, playlist.GetList()[4].ID);
 }
Esempio n. 4
0
 public Status AddToList(Song[] songMas, int index)
 {
     //_ListOfSongs.InsertRange(index, songMas);
     songMas.Reverse();
     foreach (Song song in songMas)
     {
         _ListOfSongs.Insert(index, song);
     }
     return Status.Ok;
 }
Esempio n. 5
0
 public void CheckIfBaseListOfSongsContainsSong(Song song)
 {
     if (_BaseListOfSongs.Contains(song))
     {
         song.AddRemoveImage = @"Resources/Pictures/ok_small.png";
     }
     else
     {
         song.AddRemoveImage = @"Resources/Pictures/ok_lightgrey.png";
     }
 }
 public void AddToList_IDOfFirstThirdAndFiftsSongsShouldBe8()
 {
     Playlist.Playlist playlist = new Playlist.Playlist();
     List<Song> songList = new List<Song>();
     songList.AddRange(new Song[] { new Song(1), new Song(2), new Song(3), new Song(4) });
     playlist.UpdateList(new ObservableCollection<Song>(songList));
     Song insertedSong = new Song(8);
     playlist.AddToList(insertedSong, 0);
     Assert.AreEqual(insertedSong.ID, playlist.GetList()[0].ID);
     playlist.AddToList(insertedSong, 5);
     Assert.AreEqual(insertedSong.ID, playlist.GetList()[5].ID);
     playlist.AddToList(insertedSong, 3);
     Assert.AreEqual(insertedSong.ID, playlist.GetList()[3].ID);
 }
Esempio n. 7
0
 public async Task DownloadAudioAync(Song song, string path, DownloadProgressChangedEventHandler ProgressChanged, AsyncCompletedEventHandler DownloadSongCallback)
 {
     try
     {
         WebClient Client = new WebClient();
         hashCodeConnection.Add(Client.GetHashCode(), song.GetHashCode());
         Client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadSongCallback);
         Client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCallback);
         Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
         await Client.DownloadFileTaskAsync(song.Uri, path);
     }
     catch
     { }
 }
 public void SaveAndLoadListOfUsers_IDOfFirstElementsOfSavedListAndLoadedListsShouldBeTheSame()
 {
     Infrastructure.Infrastructure infrastructure = new Infrastructure.Infrastructure();
     List<Song> songList = new List<Song>();
     Song song1 = new Song(1);
     Song song2 = new Song(2);
     songList.AddRange(new Song[] { song1, song2 });
     List<User> userList = new List<User>();
     User user1 = new User("some1", "id1", songList);
     User user2 = new User("some2", "id2", songList);
     userList.AddRange(new User[] { user1, user2 });
     infrastructure.SaveListOfUsers(userList);
     List<User> userList2 = new List<User>();
     userList2 = infrastructure.LoadListOfUsers();
     Assert.AreEqual(userList[1].SongList[1].ID, userList2[1].SongList[1].ID, "Сериализация прошла некорректно");
 }
Esempio n. 9
0
 public void CheckIfDownloaded(Song song)
 {
     string folder = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) + @"\VVKMusic\";
     string fileName = song.Artist + "-" + song.Title + ".mp3";
     if (song.DownloadedUri == null)
         song.DownloadedUri = new Uri(@folder + fileName);
     string path = @folder + @fileName;
     if (File.Exists(path))
     {
         song.Downloaded = true;
         song.DownloadImage = @"Resources/Pictures/ok_small.png";
     }
     else
     {
         song.Downloaded = false;
         song.DownloadImage = @"Resources/Pictures/ok_lightgrey.png";
     }
 }
Esempio n. 10
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                string albumId = collection["AlbumId"];
                string name    = collection["Name"];
                string artist  = collection["Artist"];
                Genre  genre   = (Genre)int.Parse(collection["Genre"]);

                var song = new Common.Song(0, name, artist, genre);
                if (!string.IsNullOrWhiteSpace(albumId))
                {
                    song.AlbumId = int.Parse(albumId);
                }

                DAL.SongRepository.Create(song);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 11
0
 public Status AddToList(Song song, int index)
 {
     _ListOfSongs.Insert(index, song);
     return Status.OK;
 }
Esempio n. 12
0
 public Status AddToList(Song[] songMas, int index)
 {
     _ListOfSongs.InsertRange(index, songMas);
     return Status.OK;
 }
Esempio n. 13
0
 public Status AddToBaseList(Song song)
 {
     _BaseListOfSongs.Insert(0, song);
     return Status.Ok;
 }
Esempio n. 14
0
 public Status RemoveFromBaseList(Song song)
 {
     _BaseListOfSongs.Remove(song);
     return Status.Ok;
 }