Пример #1
0
        public void LoadFile(Database.Song sr, int index)
        {
            this._row = sr;
            this._index = index;

            string filename = sr.Path + "\\" + sr.Filename;

            if (System.IO.File.Exists(filename))
            {
                ResetAll();
                txtFile.Text = filename;
                decoder.Load(filename);

                int bits = decoder.SourceBitDepth;
                int channels = decoder.SourceChannels;

                if (decoder.Ready)
                {
                    lbAudio.Content = String.Format("{0}Hz, {1}bit{2}, {3}",
                        decoder.SourceSampleRate, bits, bits != 16 ? " (not supported)" : "",
                        channels == 2 ? "stereo" : (channels == 1 ? "mono" : "multi-channel"));

                    lbDuration.Content = decoder.Duration.ToString();

                    LoadTags(filename);

                    btnFingerprint.IsEnabled = true;
                }
                else
                {
                    lbAudio.Content = "Failed to load audio";
                    lbDuration.Content = String.Empty;
                }
            }
        }
Пример #2
0
        public void StartTagging()
        {
            wndMainWindow = this.Owner as MainWindow;

            UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(pbProgress.SetValue);
            UpdateProgressTextDelegate updatePtDelegate = new UpdateProgressTextDelegate(txtResults.SetValue);
            double i = 0.0;
            int total = wndMainWindow.AudioEngine.Playlist.Count;
            pbProgress.Minimum = i;
            pbProgress.Maximum = total;
            string t = "Initializing...";
            int idx = 0;

            int c = wndMainWindow.AudioEngine.Playlist.Count();
            Database.Song[] temp = new Database.Song[c];
            wndMainWindow.AudioEngine.Playlist.CopyTo(temp, 0);
            // can't modify the playlist if its the subject of the foreach, so we have to make a copy.


            foreach (Database.Song row in temp)
            {
                i++;
                t += "\n" + "Processing file " + i.ToString() + " of " + total.ToString() + " | " + row.Filename;

                Dispatcher.Invoke(updatePtDelegate,
                    System.Windows.Threading.DispatcherPriority.Background,
                    new object[] { TextBox.TextProperty, t });

                AudioEngine.Fingerprint(row);

                wndMainWindow.AudioEngine.Playlist.RemoveAt(idx);
                wndMainWindow.AudioEngine.Playlist.Insert(idx, row);

                Dispatcher.Invoke(updatePbDelegate,
                    System.Windows.Threading.DispatcherPriority.Background,
                    new object[] { ProgressBar.ValueProperty, i });

                idx++;
            }

            this.btnClose.IsEnabled = true;
        }
Пример #3
0
        public void PlayItem(int index)
        {
            if (index > -1 && index < this.Playlist.Count)
            {
                iSelectedIndex = index;
                activeItem = Playlist[index];
                TrackChangeData e = new TrackChangeData();
                e.index = index;
                TrackChange(this, e);
                string file = activeItem.Path + "\\" + activeItem.Filename;
                Console.WriteLine("Trying to play file: " + file);

                engine.OpenFile(file);
                if (engine.CanPlay)
                {
                    TagLib.File f = engine.FileTag;
                    TagLib.Tag tag = f.Tag;

                    string ititle = activeItem.Title == null ? tag.Title : activeItem.Title;
                    string iartist = activeItem.Artist == null ? tag.AlbumArtists[0] : activeItem.Artist;
                    string ialbumtrack = "Track " + (activeItem.Track == null ? tag.Track.ToString() : activeItem.Track) + " on " + (activeItem.Album == null ? tag.Album : activeItem.Album);
                    string iyear = activeItem.Year == null ? tag.Year.ToString() : activeItem.Year;

                    if (iyear != "")
                    {
                        iyear = "released in " + iyear;
                    }

                    ImageData id = new ImageData();
                    id.Image = GetAlbumArt(activeItem.Artist, activeItem.Album);
                    ImageLoad(this, id);
                    TagData td = new TagData();
                    td.artist = iartist;
                    td.title = ititle;
                    td.year = iyear;
                    td.trackalbum = ialbumtrack;
                    TagLoad(this, td);

                    engine.Volume = fVolume;
                    engine.Play();
                    engine.PlaybackStopped += Engine_PlaybackStopped;

                }

            }
        }