public Status StopAndStopTimer()
 {
     _updateTimer.Stop();
     if (Bass.BASS_ChannelStop(_stream))
     {
         return(Status.OK);
     }
     else
     {
         return(Status.Error);
     }
 }
Пример #2
0
 public void Play(float volume)
 {
     _timer.Stop();
     if (!_isopened)
     {
         return;
     }
     if (_channel != 0 && Bass.BASS_ChannelPlay(_channel, true))
     {
         _timer.Start();
         _isPaused = false;
     }
     else
     {
         throw new FormatException(Bass.BASS_ErrorGetCode().ToString());
     }
     Volume = volume;
 }
Пример #3
0
        void BassTimer_Tick(object sender, EventArgs e)
        {
            PlayerProgressInformation progress = new PlayerProgressInformation();
            BASSActive state = Bass.BASS_ChannelIsActive(BassStream);

            if (state == BASSActive.BASS_ACTIVE_PLAYING)
            {
                progress.state = PlayState.PLAYING;
            }
            else if (state == BASSActive.BASS_ACTIVE_PAUSED)
            {
                progress.state = PlayState.PAUSED;
            }
            else if (state == BASSActive.BASS_ACTIVE_STOPPED)
            {
                progress.state = PlayState.STOPPED;
            }
            else if (state == BASSActive.BASS_ACTIVE_STALLED)
            {
                progress.state = PlayState.STALLED;
            }

            if (TagInfo != null)
            {
                progress.artist = TagInfo.artist;
                progress.track  = TagInfo.title;
            }
            double totaltime, elapsedtime;

            if (state != BASSActive.BASS_ACTIVE_STOPPED)
            {
                long pos = Bass.BASS_ChannelGetPosition(BassStream);           // position in bytes
                long len = Bass.BASS_ChannelGetLength(BassStream);             // length in bytes
                totaltime   = Bass.BASS_ChannelBytes2Seconds(BassStream, len); // the total time length
                elapsedtime = Bass.BASS_ChannelBytes2Seconds(BassStream, pos); // the elapsed time length
            }
            else
            {
                totaltime = elapsedtime = 0;
            }



            progress.totalLength     = (int)totaltime;
            progress.currentPosition = (int)elapsedtime;


            Program.playerWindow.Invoke(new neprostopleer.PlayerWindow.UpdateGUIStatusDelegate(Program.playerWindow.UpdateGUIStatus), new object[] { progress });

            if (Bass.BASS_ChannelIsActive(BassStream) != BASSActive.BASS_ACTIVE_PLAYING)
            {
                BassTimer.Stop();
            }
        }
Пример #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            _updateTimer.Stop();
            Bass.BASS_StreamFree(stream);

            if (favorites.Count > 0 && playFavorites.Checked)
            {
                song = int.Parse(favorites[favoriteIndex]);
                favoriteIndex++;

                if (favoriteIndex >= favorites.Count)
                {
                    favoriteIndex = 0;
                }
            }
            else
            {
                song = rand.Next(1, 189357);
            }

            isFavorite.Checked = isFavorited(song);

            using (var client = new WebClient())
            {
                client.DownloadFile($@"https://api.modarchive.org/downloads.php?moduleid={song}", "song.tmp");
            }

            lblSong.Text = $"Mod Archive #{song}";
            lblSong.Tag  = song;

            stream = Bass.BASS_StreamCreateFile(@"song.tmp", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);

            myDSPAddr = new DSPPROC(MyDSPGainUnsafe);
            Bass.BASS_ChannelSetDSP(stream, myDSPAddr, IntPtr.Zero, 2);

            Bass.BASS_ChannelPlay(stream, true);
            _updateTimer.Start();
        }
Пример #5
0
        private void timerUpdate_Tick(object sender, EventArgs e)
        {
            // here we gather info about the stream, when it is playing...
            if (Bass.BASS_ChannelIsActive(_stream) != BASSActive.BASS_ACTIVE_PLAYING &&
                Bass.BASS_ChannelIsActive(_stream) != BASSActive.BASS_ACTIVE_PAUSED)
            {
                // the stream is NOT playing anymore...
                _updateTimer.Stop();
                playBackSlider.Value     = 0;
                pictureBoxSpectrum.Image = null;
                return;
            }

            // from here on, the stream is for sure playing...
            _tickCounter++;

            if (_tickCounter == 5)
            {
                // display the position every 250ms (since timer is 50ms)
                _tickCounter = 0;
                double elapsedtime = Bass.BASS_ChannelBytes2Seconds(_stream, Bass.BASS_ChannelGetPosition(_stream));
                // the elapsed time length
                string timeFormatted = String.Format("{0:#0:00}", Utils.FixTimespan(elapsedtime, "MMSS"));

                // Move the PlaybackSlider
                playBackSlider.Value = (int)(Math.Round((elapsedtime / _songLength), 2) * 100.0);

                // Now Paint the time to the Picturebox
                Graphics g = Graphics.FromHwnd(pictureBoxTime.Handle);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.Clear(Color.Black);
                g.DrawString(timeFormatted, new Font("Verdana", 18), new SolidBrush(Color.CornflowerBlue), 0, 0);
                g.Dispose();
            }

            // update spectrum
            DrawSpectrum();
        }
Пример #6
0
 /// <summary>
 ///     Unloads this instance.
 /// </summary>
 public void Unload()
 {
     BassPlayer.UnloadRawLoopTrack();
     _timer.Stop();
 }
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
                Title      = _title;
                NeteaseUrl = "http://music.163.com/#/my/m/music/playlist?id=6435531";
                SongCollection.Add(new Song()
                {
                    Title   = new Title("Clover Heart's"),
                    Artists = new Artists(new string[] { "榊原ゆい", "榊原ゆい" }),
                    Album   = new Album("Boommmmm", "http://p4.music.126.net/n189nEFRefNaucKD8akNQw==/7886796906449604.jpg"),
                });
                SongCollection.Add(new Song()
                {
                    Title   = new Title("Clover Heart's"),
                    Artists = new Artists(new string[] { "榊原ゆい" }),
                    Album   = new Album("Boommmmm", "http://p4.music.126.net/n189nEFRefNaucKD8akNQw==/7886796906449604.jpg"),
                });
                SongCollection.Add(new Song()
                {
                    Title   = new Title("Clover Heart's"),
                    Artists = new Artists(new string[] { "榊原ゆい" }),
                    Album   = new Album("Boommmmm", "http://p4.music.126.net/n189nEFRefNaucKD8akNQw==/7886796906449604.jpg"),
                });
                SelectedSong = SongCollection.First();
            }
            else
            {
                // Code runs "for real"
                Title                      = _title;
                NeteaseUrl                 = "http://music.163.com/playlist?id=6435531";
                Progress                   = 0;
                audioPlayback              = new AudioPlayback();
                audioPlayback.Volume       = Volume;
                audioPlayback.EndCallback += (handle, channel, data, user) =>
                {
                    int index = -1;
                    if ((index = SongCollection.IndexOf(CurrentPlaySong)) != -1)
                    {
                        ListenCommand.Execute(SongCollection.ElementAt((index + 1) % SongCollection.Count));
                    }
                    else
                    {
                        audioPlayback.Stop();
                        NowPlaying = "";
                        CurrentPlaySong.PlayProgress = 0;
                        CurrentPlaySong.PlayStatus   = PlayStatus.Play;
                        timer.Enabled = false;
                        timer.Stop();
                    }
                };

                timer.Tick += (sender, args) =>
                {
                    Title = string.Format("{0}/{1} - {2}", audioPlayback.CurrentLength, audioPlayback.TotalLength, _title);
                    RaisePropertyChanged("Title");
                    CurrentPlaySong.PlayProgress = audioPlayback.Progress;
                };

                GetSongsCommand = new RelayCommand(async() =>
                {
                    if (string.IsNullOrWhiteSpace(NeteaseUrl))
                    {
                        return;
                    }
                    var id      = "";
                    var urlType = "";
                    var reg     = new Regex(@".*/(.*?)\?id=(\d*)").Match(NeteaseUrl);
                    if (reg.Success)
                    {
                        urlType = reg.Groups[1].Value;
                        id      = reg.Groups[2].Value;
                        SongCollection.Clear();
                        switch (urlType)
                        {
                        case "album":
                            foreach (var song in await NeteaseUtil.GetSongsFromAlbum(id))
                            {
                                SongCollection.Add(song);
                                RaisePropertyChanged("TotalCount");
                            }
                            break;

                        case "artist":
                            foreach (var song in await NeteaseUtil.GetSongsFromArtist(id))
                            {
                                SongCollection.Add(song);
                                RaisePropertyChanged("TotalCount");
                            }
                            break;

                        case "playlist":
                            foreach (var song in await NeteaseUtil.GetSongsFromPlaylist(id))
                            {
                                SongCollection.Add(song);
                                RaisePropertyChanged("TotalCount");
                            }
                            break;

                        case "song":
                            foreach (var song in await NeteaseUtil.GetSongDetail(id))
                            {
                                SongCollection.Add(song);
                                RaisePropertyChanged("TotalCount");
                            }
                            break;
                        }
                    }
                    else
                    {
                        SongCollection.Clear();
                        foreach (var song in await NeteaseUtil.SearchSongs(NeteaseUrl))
                        {
                            SongCollection.Add(song);
                            RaisePropertyChanged("TotalCount");
                        }
                    }
                });

                PlaylistDownloadCommand = new RelayCommand <Song>((song) =>
                {
                    SelectedSong = song;
                    if (string.IsNullOrWhiteSpace(SongTrackUrl))
                    {
                        return;
                    }
                    var downloader = new DownloadUtils();
                    downloader.DownloadProgressChanged += (sender, args) =>
                    {
                        song.DownProgress   = args.ProgressPercentage;
                        BytesReceived       = args.BytesReceived.ToString();
                        TotalBytesToReceive = args.TotalBytesToReceive.ToString();
                    };
                    downloader.DownloadFileCompleted += (sender, args) =>
                    {
                        if (DownloadNext)
                        {
                            int index = -1;
                            if ((index = SongCollection.IndexOf(song)) != -1 && index + 1 < SongCollection.Count)
                            {
                                PlaylistDownloadCommand.Execute(SongCollection.ElementAt(index + 1));
                            }
                        }
                        else
                        {
                            BytesReceived       = "0";
                            TotalBytesToReceive = "0";
                        }
                    };
                    downloader.Get(SongTrackUrl, Path.Combine("music", FileUtils.GetSafeFileName(song.SongFileName)));
                });

                ListenCommand = new RelayCommand <Song>((song) =>
                {
                    SelectedSong = song;
                    if (string.IsNullOrWhiteSpace(SongTrackUrl))
                    {
                        return;
                    }
                    if (song.PlayStatus == PlayStatus.Play)
                    {
                        if (CurrentPlaySong != null && CurrentPlaySong != song)
                        {
                            audioPlayback.Stop();
                            CurrentPlaySong.PlayProgress = 0;
                            CurrentPlaySong.PlayStatus   = PlayStatus.Play;
                        }

                        audioPlayback.Load(SongTrackUrl);
                        audioPlayback.Play();

                        CurrentPlaySong = song;
                        NowPlaying      = string.Format("Now Playing {0} - {1}", song.Artists, song.Title);
                        timer.Enabled   = true;
                        timer.Start();
                        song.PlayProgress = 0;
                        song.PlayStatus   = PlayStatus.Stop;
                    }
                    else
                    {
                        audioPlayback.Stop();
                        NowPlaying        = "";
                        song.PlayStatus   = PlayStatus.Play;
                        song.PlayProgress = 0;
                        timer.Enabled     = false;
                        timer.Stop();
                    }
                });

                OpenUrlCommand = new RelayCommand <string>((link) =>
                {
                    System.Diagnostics.Process.Start(link);
                });

                CopyUrlCommand = new RelayCommand <string>((link) =>
                {
                    Clipboard.SetText(link);
                });

                WindowClosing = new RelayCommand(() =>
                {
                    Properties.Settings.Default.Save();
                });
            }
        }