Example #1
0
        private void Ellipse_PointerExited(object sender, PointerRoutedEventArgs e)
        {
            var img = (sender as Image);
            var tmp = Helper.base64toBmp((img.DataContext as Song).Thumbnail);

            img.Stretch = Stretch.Fill;
            img.Source  = tmp;
        }
Example #2
0
        private void Image_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            var img = (sender as Image);

            if (img.DataContext as Song != null)
            {
                var tmp = Helper.base64toBmp((img.DataContext as Song).Thumbnail);
                img.Stretch = Stretch.Fill;
                img.Source  = tmp;
            }
        }
Example #3
0
        public async void Play()
        {
            if (currentSong == null && currentPlaylist == null)
            {
                return;
            }

            if (currentPlaylist != null && currentSong == null)
            {
                this.currentSong = currentPlaylist.Songlist.FirstOrDefault();
            }

            if (currentSong.isDownloaded)
            {
                try
                {
                    StorageFolder sf = await StorageFolder.GetFolderFromPathAsync(currentSong.downloadPath);

                    var storageFile = await sf.GetFileAsync(currentSong.DownloadTitle + ".mp3");

                    this.mPlayer.Source = MediaSource.CreateFromStorageFile(storageFile);
                    this.mPlayer.Play();
                }
                catch (FileNotFoundException) {
                    Helper.ErrorDialog("Song not found!", "File was probably deleted. Please download it again.");
                    var i = currentPlaylist.Songlist.IndexOf(currentSong);
                    currentSong.isDownloaded = false;
                    currentPlaylist.Songlist.RemoveAt(i);
                    currentPlaylist.Songlist.Insert(i, currentSong);
                    await DataIO.SavePlaylist(currentPlaylist);

                    skipSong();
                    //TODO: update UI
                    return;
                }
            }
            else
            {
                //if (!Helper.checkIfOnline())
                //    return;
                try
                {
                    var stream = await this.GetAudioStream(currentSong.SongURL);

                    this.mPlayer.Source = MediaSource.CreateFromUri(new Uri(stream));
                    this.mPlayer.Play();
                }
                catch (System.Net.Http.HttpRequestException)
                {
                    return;
                }
                catch (NullReferenceException) {
                    //happens if "video" is not playable for some reason
                    Helper.ErrorDialog("Cant Play this Song", "For some reason this song can't be played.");
                    skipSong();
                    return;
                }
            }

            Helper.executeInUiThread(() =>
            {
                this.StartLogoStackPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                this.currPlayingRect.Fill           = new ImageBrush
                {
                    ImageSource = Helper.base64toBmp(currentSong.Thumbnail)
                };
                this.currPlayingLabel.Text = currentSong.Title;
            });

            this.smtc.IsNextEnabled            = true;
            this.smtc.IsPlayEnabled            = true;
            this.smtc.IsPauseEnabled           = true;
            this.smtc.IsPreviousEnabled        = true;
            this.smtc.DisplayUpdater.Thumbnail = RandomAccessStreamReference.CreateFromStream(await Helper.base64toStream(currentSong.Thumbnail));
            this.smtc.DisplayUpdater.Update();
        }