/// <summary>
        /// Converts a track to MP3 and sets the Status in the list view
        /// </summary>
        /// <param name="track">Track Object which should be converted</param>
        protected void convertTrack(RecordedTrack track)
        {
            string newPath = track.Path.Replace(".wav", ".mp3");
            int itemIndex = 0;

            SpotRecorderWindow.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, TimeSpan.FromSeconds(3), new Action(
                delegate()
                {
                    int counter = 0;
                    foreach (RecordedTrack r in _recordedTracks)
                    {
                        if (r.Path.Equals(track.Path))
                        {
                            itemIndex = counter;
                            _recordedTracks[counter].Status = "Converting...";
                            lv_recordedTracks.Items.Refresh();
                            break;
                        }
                        counter++;
                    }
                }
                ));

            System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
            psi.FileName = "ffmpeg.exe";
            psi.CreateNoWindow = true;
            psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            psi.Arguments = string.Format("-i \"{0}\" -acodec libmp3lame -ab 192k -ac 2 -y \"{1}\"", track.Path, newPath);
            System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
            p.WaitForExit();

            SpotRecorderWindow.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, TimeSpan.FromSeconds(3), new Action(
                delegate()
                {
                    if (File.Exists(newPath))
                    {
                        File.Delete(track.Path);
                        track.Status = "Converted";
                        track.Path = track.Path.Replace(".wav", ".mp3");
                        _recordedTracks[itemIndex] = track;
                    }
                    else
                    {
                        track.Status = "Converting Error";
                        _recordedTracks[itemIndex] = track;
                    }
                    lv_recordedTracks.Items.Refresh();
                }
                ));

            tagTrack(track, itemIndex);
        }
        /// <summary>
        /// Tags a File and sets status in the listview
        /// </summary>
        /// <param name="track">SpotTrack-Object which should be tagged</param>
        /// <param name="listViewIndex">Index of the listview</param>
        protected void tagTrack(RecordedTrack track, int listViewIndex)
        {
            if (File.Exists(track.Path))
            {
                TagLib.File f = TagLib.File.Create(track.Path);

                if (!string.IsNullOrEmpty(track.Title))
                {
                    f.Tag.Title = track.Title;
                }

                if (!string.IsNullOrEmpty(track.Artist))
                {
                    f.Tag.Performers = new string[] { track.Artist };
                }

                try
                {
                    f.Save();

                    SpotRecorderWindow.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
                        delegate()
                        {
                            _recordedTracks[listViewIndex].Status = "Finished";
                            lv_recordedTracks.Items.Refresh();
                        }
                        ));

                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #3
0
 public static RecordedTrack convertSpotTrack(SpotTrack track)
 {
     RecordedTrack r = new RecordedTrack(track.Artist, track.Title);
     r.Path = track.Path;
     return r;
 }