Exemplo n.º 1
0
        public IProcessingPluginChain AddOutputDevicePlugin(IOutputDevicePlugin plugin, IOutputDevicePluginContext startingContext)
        {
            var outputDevices = OutputDevices.ToList();

            outputDevices.Add(new OutputDevice(plugin, startingContext));
            OutputDevices = outputDevices;

            return(this);
        }
Exemplo n.º 2
0
 public static IOutputDevicePluginContext GenerateInitialOutputDevicePluginContext(IOutputDevicePlugin outputDevicePlugin)
 {
     return(new OutputDevicePluginContext(outputDevicePlugin.Configure()));
 }
Exemplo n.º 3
0
 internal OutputDevice(IOutputDevicePlugin plugin, IOutputDevicePluginContext context)
 {
     Plugin  = plugin;
     Context = context;
 }
        public void Play()
        {
            if (String.IsNullOrEmpty(AudioFile) || !System.IO.File.Exists(AudioFile))
            {
                OnOpenFileClick(null, null);
            }

            if (String.IsNullOrEmpty(AudioFile))
            {
                return;
            }

            switch (Preferences.OutputDevice)
            {
            case "WaveOut":
                for (int deviceId = 0; deviceId < WaveOut.DeviceCount; deviceId++)
                {
                    var capabilities = WaveOut.GetCapabilities(deviceId);
                }

                WaveCallbackStrategy strategy = WaveCallbackStrategy.NewWindow;
                if (Preferences.WaveOutCallback == "Function")
                {
                    strategy = WaveCallbackStrategy.FunctionCallback;
                }
                if (Preferences.WaveOutCallback == "Window")
                {
                    strategy = WaveCallbackStrategy.NewWindow;
                }
                if (Preferences.WaveOutCallback == "Event")
                {
                    strategy = WaveCallbackStrategy.Event;
                }

                m_SelectedOutputDevicePlugin = new WaveOutPlugin(strategy, Preferences.WaveOutDevice);

                break;

            case "WasapiOut":
                var endPoints = new MMDeviceEnumerator().EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
                m_SelectedOutputDevicePlugin = new WasapiOutPlugin(
                    endPoints[Preferences.WasapiOutDevice],
                    Preferences.WasapiOutExclusiveMode == "True" ? AudioClientShareMode.Exclusive : AudioClientShareMode.Shared,
                    Preferences.WasapiOutIsEventCallback == "True",
                    Preferences.RequestedLatency);

                break;

            case "NullOut":
                string output;
                string player = MainWindow.iniFile.GetString("Externals", "AudioPlayer", "C:\\Program Files (x86)\\AIMP2\\AIMP2.exe");
                if (!player.Contains(":"))
                {
                    //player = System.IO.Path.Combine(Environment.CurrentDirectory, player);
                }
                FileExecutionHelper.ExecutionHelper.RunCmdCommand(
                    "\"" + player + "\" " +
                    "\"" + AudioFile + "\"", out output, false, 1251);
                return;

            //break;
            case "DirectSound":
            default:
                m_SelectedOutputDevicePlugin = new DirectSoundOutPlugin();
                break;
            }



            if (!m_SelectedOutputDevicePlugin.IsAvailable)
            {
                MessageBox.Show("The selected output driver is not available on this system");
                return;
            }

            if (m_WaveOut != null)
            {
                if (m_WaveOut.PlaybackState == PlaybackState.Playing)
                {
                    return;
                }
                else if (m_WaveOut.PlaybackState == PlaybackState.Paused)
                {
                    System.Threading.Tasks.Task.Factory.StartNew(new Action(() =>
                    {
                        m_WaveOut.Play();
                    }));

                    return;
                }
            }

            // we are in a stopped state
            try
            {
                CreateWaveOut();

                m_DispatcherTimer.Start();

                Dispatcher.Invoke(delegate { LoadTrackTags(); });
            }
            catch (TagLib.CorruptFileException tagLibCorruptFileException)
            {
                Dispatcher.Invoke(delegate { TextBlockTrackTitle.Text = string.Format("{0}  {1}", System.IO.Path.GetFileName(AudioFile), tagLibCorruptFileException.Message); });
            }
            catch (Exception driverCreateException)
            {
                Core.CommandHelper.Log(String.Format("driverCreateException {0}", driverCreateException.Message));
                //MessageBox.Show(String.Format("driverCreateException {0}", driverCreateException.Message));
                return;
            }

            sampleProvider = null;
            try
            {
                sampleProvider = CreateInputStream(AudioFile);
            }
            catch (Exception createException)
            {
                Core.CommandHelper.Log(String.Format("createException {0}", createException.Message));
                //MessageBox.Show(String.Format("createException {0}", createException.Message), "Error Loading File");
                return;
            }

            try
            {
                //if (m_FadeInOutSampleProvider != null && !(audioFileReader is FlacReader))
                //    waveOut.Init(m_FadeInOutSampleProvider);
                //else
                m_WaveOut.Init(sampleProvider);
            }
            catch (Exception initException)
            {
                Core.CommandHelper.Log(String.Format("initException {0}", initException.Message));
                //MessageBox.Show(String.Format("initException {0}", initException.Message), "Error Initializing Output");
                return;
            }


            Dispatcher.Invoke(delegate { InvokeSetVolumeDelegate((float)SliderVolume.Value); });
            System.Threading.Tasks.Task.Factory.StartNew(new Action(() =>
            {
                m_WaveOut.Play();
                sampleAggregator = new SampleAggregator(fftDataSize);
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsPlaying"));
            }));

            //try
            //{
            //    System.Threading.Tasks.Task.Factory.StartNew(new Action(() =>
            //    {
            //        InitWaveformPainter(sampleProvider);
            //    }));

            //}
            //catch (Exception waveFormException)
            //{
            //    MessageBox.Show(String.Format("waveFormException {0}", waveFormException.Message), "Error Initializing Output");
            //    return;
            //}
        }