public void addAudioCallback(AudioCallbacks callback) { if (callbacks == null) { callbacks = new List <AudioCallbacks>(); } callbacks.Add(callback); }
public void SetCallbacks(AudioCallbacks callbacks) { if (callbacks.SoundCallback == null) { throw new ArgumentNullException("Sound playback callback must be set"); } m_callbacks = callbacks; LibVlcMethods.libvlc_audio_set_callbacks(m_hMediaPlayer, m_hSound, m_hPause, m_hResume, m_hFlush, m_hDrain, IntPtr.Zero); LibVlcMethods.libvlc_audio_set_volume_callback(m_hMediaPlayer, m_hVolume); }
protected override void Dispose(bool disposing) { LibVlcMethods.libvlc_audio_set_format_callbacks(m_hMediaPlayer, IntPtr.Zero, IntPtr.Zero); LibVlcMethods.libvlc_audio_set_callbacks(m_hMediaPlayer, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); if (disposing) { m_formatSetupCB = null; m_callbacks = null; m_callbacksDelegates.Clear(); } }
/// <summary> /// Start audio source. /// </summary> /// /// <remarks>Starts audio source and return execution to caller. audio source /// object creates background thread and notifies about new frames with the /// help of <see cref="DataAvailable"/> event.</remarks> /// /// <exception cref="ArgumentException">audio source is not specified.</exception> /// public void Start() { if (!VlcHelper.VlcInstalled) { return; } if (!IsRunning) { // check source if (string.IsNullOrEmpty(_source)) { throw new ArgumentException("Audio source is not specified."); } DisposePlayer(); _mFactory = new MediaPlayerFactory(false); _mPlayer = _mFactory.CreatePlayer <IVideoPlayer>(); _mPlayer.Events.PlayerPlaying += EventsPlayerPlaying; _mPlayer.Events.PlayerStopped += EventsPlayerStopped; _mPlayer.Events.PlayerEncounteredError += EventsPlayerEncounteredError; string[] args = Arguments.Trim(',').Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); List <String> inargs = args.ToList(); inargs.Add(":sout=#transcode{vcodec=none}:Display"); _mMedia = _mFactory.CreateMedia <IMedia>(_source, inargs.ToArray()); _mPlayer.Open(_mMedia); GC.KeepAlive(_mFactory); GC.KeepAlive(_mPlayer); GC.KeepAlive(_mMedia); _needsSetup = true; var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback); _mPlayer.CustomAudioRenderer.SetFormatCallback(fc); //.SetFormat(new SoundFormat(SoundType.S16N, RecordingFormat.SampleRate, RecordingFormat.Channels))); var ac = new AudioCallbacks { SoundCallback = SoundCallback }; _mPlayer.CustomAudioRenderer.SetCallbacks(ac); _mMedia.Parse(false); _mPlayer.Play(); } }
protected override void Dispose(bool disposing) { NativeMethods.libvlc_audio_set_format_callbacks(m_hMediaPlayer, IntPtr.Zero, IntPtr.Zero); NativeMethods.libvlc_audio_set_callbacks(m_hMediaPlayer, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); if (disposing) { m_timer.Dispose(); m_formatSetupCB = null; m_excHandler = null; m_callbacks = null; m_callbacksDelegates.Clear(); } }
/// <summary> /// Start video source. /// </summary> /// /// <remarks>Starts video source and return execution to caller. Video source /// object creates background thread and notifies about new frames with the /// help of <see cref="NewFrame"/> event.</remarks> /// /// <exception cref="ArgumentException">Video source is not specified.</exception> /// public void Start() { if (!VlcHelper.VlcInstalled) { return; } Isstopping = false; if (!IsRunning && !_starting) { _starting = true; // check source if (string.IsNullOrEmpty(_source)) { throw new ArgumentException("Video source is not specified."); } DisposePlayer(); _mFactory = new MediaPlayerFactory(false); _mPlayer = _mFactory.CreatePlayer <IVideoPlayer>(); _mPlayer.Events.PlayerPlaying += EventsPlayerPlaying; _mPlayer.Events.PlayerStopped += EventsPlayerStopped; _mPlayer.Events.PlayerEncounteredError += EventsPlayerEncounteredError; _mMedia = _mFactory.CreateMedia <IMedia>(_source, Arguments); _mPlayer.Open(_mMedia); GC.KeepAlive(_mFactory); GC.KeepAlive(_mPlayer); GC.KeepAlive(_mMedia); _needsSetup = true; var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback); _mPlayer.CustomAudioRenderer.SetFormatCallback(fc); var ac = new AudioCallbacks { SoundCallback = SoundCallback }; _mPlayer.CustomAudioRenderer.SetCallbacks(ac); _mPlayer.CustomRenderer.SetFormat(new BitmapFormat(FormatWidth, FormatHeight, ChromaType.RV24)); _mPlayer.CustomRenderer.SetCallback(FrameCallback); _mMedia.Parse(true); _framesReceived = 0; _mPlayer.Play(); } }
public void removeAudioCallback(AudioCallbacks callback) { this.callbacks.Remove(callback); }
public void addAudioCallback(AudioCallbacks callback) { this.callbacks.Add(callback); //Debug.Log(callback); }
private void WorkerThread() { bool file = false; try { if (File.Exists(_source)) { file = true; } } catch { } if (_mFactory == null) { var args = new List <string> { "-I", "dumy", "--ignore-config", "--no-osd", "--disable-screensaver", "--plugin-path=./plugins" }; if (file) { args.Add("--file-caching=3000"); } try { var l2 = args.ToList(); l2.AddRange(_arguments); l2 = l2.Distinct().ToList(); _mFactory = new MediaPlayerFactory(l2.ToArray()); } catch (Exception ex) { MainForm.LogExceptionToFile(ex); MainForm.LogMessageToFile("VLC arguments are: " + String.Join(",", args.ToArray())); MainForm.LogMessageToFile("Using default VLC configuration."); _mFactory = new MediaPlayerFactory(args.ToArray()); } GC.KeepAlive(_mFactory); } if (file) { _mMedia = _mFactory.CreateMedia <IMediaFromFile>(_source); } else { _mMedia = _mFactory.CreateMedia <IMedia>(_source); } _mMedia.Events.DurationChanged += EventsDurationChanged; _mMedia.Events.StateChanged += EventsStateChanged; if (_mPlayer != null) { try { _mPlayer.Dispose(); } catch { } _mPlayer = null; } _mPlayer = _mFactory.CreatePlayer <IVideoPlayer>(); _mPlayer.Events.TimeChanged += EventsTimeChanged; var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback); _mPlayer.CustomAudioRenderer.SetFormatCallback(fc); var ac = new AudioCallbacks { SoundCallback = SoundCallback }; _mPlayer.CustomAudioRenderer.SetCallbacks(ac); _mPlayer.CustomAudioRenderer.SetExceptionHandler(Handler); _mPlayer.CustomRenderer.SetCallback(FrameCallback); _mPlayer.CustomRenderer.SetExceptionHandler(Handler); GC.KeepAlive(_mPlayer); _needsSetup = true; _stopping = false; _mPlayer.CustomRenderer.SetFormat(new BitmapFormat(FormatWidth, FormatHeight, ChromaType.RV24)); _mPlayer.Open(_mMedia); _mMedia.Parse(true); _mPlayer.Delay = 0; _framesReceived = 0; Duration = Time = 0; LastFrame = DateTime.MinValue; //check if file source (isseekable in _mPlayer is not reliable) Seekable = false; try { var p = Path.GetFullPath(_mMedia.Input); Seekable = !String.IsNullOrEmpty(p); } catch (Exception) { Seekable = false; } _mPlayer.WindowHandle = IntPtr.Zero; _mPlayer.Play(); _stopEvent.WaitOne(); if (!Seekable && !_stopRequested) { if (PlayingFinished != null) { PlayingFinished(this, ReasonToFinishPlaying.DeviceLost); } if (AudioFinished != null) { AudioFinished(this, ReasonToFinishPlaying.DeviceLost); } } else { if (PlayingFinished != null) { PlayingFinished(this, ReasonToFinishPlaying.StoppedByUser); } if (AudioFinished != null) { AudioFinished(this, ReasonToFinishPlaying.StoppedByUser); } } DisposePlayer(); }
private void WorkerThread() { bool file = false; try { if (File.Exists(Source)) { file = true; } } catch { // ignored } if (_mFactory == null) { var args = new List <string> { "-I", "dumy", "--ignore-config", "--no-osd", "--disable-screensaver", "--plugin-path=./plugins" }; if (file) { args.Add("--file-caching=3000"); } try { var l2 = args.ToList(); l2.AddRange(_arguments); l2 = l2.Distinct().ToList(); _mFactory = new MediaPlayerFactory(l2.ToArray()); } catch (Exception ex) { Logger.LogException(ex, "VLC Stream"); Logger.LogMessage("VLC arguments are: " + string.Join(",", args.ToArray()), "VLC Stream"); Logger.LogMessage("Using default VLC configuration.", "VLC Stream"); _mFactory = new MediaPlayerFactory(args.ToArray()); } GC.KeepAlive(_mFactory); } var vss = Source; if (!_modeAudio) { vss = Tokenise(vss); } _mMedia = file ? _mFactory.CreateMedia <IMediaFromFile>(vss) : _mFactory.CreateMedia <IMedia>(vss); _mMedia.Events.DurationChanged += EventsDurationChanged; _mMedia.Events.StateChanged += EventsStateChanged; if (_mPlayer != null) { try { _mPlayer?.Dispose(); } catch { // ignored } _mPlayer = null; } _mPlayer = _mFactory.CreatePlayer <IVideoPlayer>(); _mPlayer.Events.TimeChanged += EventsTimeChanged; var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback); _mPlayer.CustomAudioRenderer.SetFormatCallback(fc); var ac = new AudioCallbacks { SoundCallback = SoundCallback }; _mPlayer.CustomAudioRenderer.SetCallbacks(ac); _mPlayer.CustomAudioRenderer.SetExceptionHandler(Handler); if (!_modeAudio) { _mPlayer.CustomRenderer.SetCallback(FrameCallback); _mPlayer.CustomRenderer.SetExceptionHandler(Handler); } GC.KeepAlive(_mPlayer); _needsSetup = true; _mPlayer.CustomRenderer.SetFormat(new BitmapFormat(_source.settings.vlcWidth, _source.settings.vlcHeight, ChromaType.RV24)); _mPlayer.Open(_mMedia); _mMedia.Parse(true); _mPlayer.Delay = 0; Duration = Time = 0; LastFrame = DateTime.MinValue; //check if file source (isseekable in _mPlayer is not reliable) Seekable = false; try { var p = Path.GetFullPath(_mMedia.Input); Seekable = !string.IsNullOrEmpty(p); } catch (Exception) { Seekable = false; } _mPlayer.WindowHandle = IntPtr.Zero; _videoQueue = new ConcurrentQueue <Bitmap>(); _audioQueue = new ConcurrentQueue <byte[]>(); _mPlayer.Play(); _abort = new ManualResetEvent(false); EventManager(); if (Seekable) { PlayingFinished?.Invoke(this, new PlayingFinishedEventArgs(ReasonToFinishPlaying.StoppedByUser)); AudioFinished?.Invoke(this, new PlayingFinishedEventArgs(ReasonToFinishPlaying.StoppedByUser)); } else { PlayingFinished?.Invoke(this, new PlayingFinishedEventArgs(_res)); AudioFinished?.Invoke(this, new PlayingFinishedEventArgs(_res)); } DisposePlayer(); _abort.Close(); }
public void addAudioCallback(AudioCallbacks callback) { this.callbacks.Add(callback); }
public void addAudioCallback(AudioCallbacks callback) { Debug.Log ("Callback: " + callback + "\nCallbacks: " + callbacks); callbacks.Add(callback); //Debug.Log(callback); }
/// <summary> /// Start video source. /// </summary> /// /// <remarks>Starts video source and return execution to caller. Video source /// object creates background thread and notifies about new frames with the /// help of <see cref="NewFrame"/> event.</remarks> /// /// <exception cref="ArgumentException">Video source is not specified.</exception> /// public void Start() { lock (_lock) { if (!VlcHelper.VlcInstalled) { return; } if (_stoprequested) { return; } if (!IsRunning && !_starting) { _starting = true; if (string.IsNullOrEmpty(_source)) { throw new ArgumentException("Video source is not specified."); } bool init = _mFactory == null; bool file = false; try { if (File.Exists(_source)) { file = true; } } catch { } if (init) { var args = new List <string> { "-I", "dumy", "--ignore-config", "--no-osd", "--disable-screensaver", "--plugin-path=./plugins" }; if (file) { args.Add("--file-caching=3000"); } _mFactory = new MediaPlayerFactory(args.ToArray()); _mPlayer = _mFactory.CreatePlayer <IVideoPlayer>(); _mPlayer.Events.PlayerPlaying += EventsPlayerPlaying; _mPlayer.Events.TimeChanged += EventsTimeChanged; var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback); _mPlayer.CustomAudioRenderer.SetFormatCallback(fc); var ac = new AudioCallbacks { SoundCallback = SoundCallback }; _mPlayer.CustomAudioRenderer.SetCallbacks(ac); _mPlayer.CustomRenderer.SetCallback(FrameCallback); _mPlayer.CustomRenderer.SetExceptionHandler(Handler); _mPlayer.CustomAudioRenderer.SetExceptionHandler(Handler); } if (file) { _mMedia = _mFactory.CreateMedia <IMediaFromFile>(_source); } else { _mMedia = _mFactory.CreateMedia <IMedia>(_source); } _mMedia.AddOptions(_arguments); _mMedia.Events.DurationChanged -= EventsDurationChanged; _mMedia.Events.StateChanged -= EventsStateChanged; _mMedia.Events.DurationChanged += EventsDurationChanged; _mMedia.Events.StateChanged += EventsStateChanged; _needsSetup = true; _mPlayer.CustomRenderer.SetFormat(new BitmapFormat(FormatWidth, FormatHeight, ChromaType.RV24)); _mPlayer.Open(_mMedia); _mMedia.Parse(true); _framesReceived = 0; Duration = Time = 0; LastFrame = DateTime.MinValue; _mPlayer.Play(); //check if file source (isseekable in _mPlayer is not reliable) Seekable = false; try { var p = Path.GetFullPath(_mMedia.Input); Seekable = !String.IsNullOrEmpty(p); } catch (Exception) { Seekable = false; } } } }
/// <summary>Removes the named callback.</summary> public void RemoveAudioCallback(AudioCallbacks callback) { callbacks.Remove(callback); }
/// <summary>Adds a callback.</summary> public void AddAudioCallback(AudioCallbacks callback) { callbacks.Add(callback); }
public void removeAudioCallback(AudioCallbacks callback) { this.callbacks.Remove(callback); }
public void addAudioCallback(AudioCallbacks callback) { this.callbacks.Add(callback); Debug.Log(callback); }
/// <summary> /// Start video source. /// </summary> /// /// <remarks>Starts video source and return execution to caller. Video source /// object creates background thread and notifies about new frames with the /// help of <see cref="NewFrame"/> event.</remarks> /// /// <exception cref="ArgumentException">Video source is not specified.</exception> /// public void Start() { lock (_lock) { if (!VlcHelper.VlcInstalled) { return; } if (_stoprequested) { return; } if (!IsRunning && !_starting) { _starting = true; // check source if (string.IsNullOrEmpty(_source)) { throw new ArgumentException("Audio source is not specified."); } bool init = _mFactory == null; if (init) { _mFactory = new MediaPlayerFactory(); _mPlayer = _mFactory.CreatePlayer <IVideoPlayer>(); _mPlayer.Events.PlayerPlaying += EventsPlayerPlaying; _mPlayer.Events.TimeChanged += EventsTimeChanged; var fc = new Func <SoundFormat, SoundFormat>(SoundFormatCallback); _mPlayer.CustomAudioRenderer.SetFormatCallback(fc); var ac = new AudioCallbacks { SoundCallback = SoundCallback }; _mPlayer.CustomAudioRenderer.SetCallbacks(ac); _mPlayer.CustomAudioRenderer.SetExceptionHandler(Handler); } bool file = false; try { if (File.Exists(_source)) { file = true; } } catch { } if (file) { _mMedia = _mFactory.CreateMedia <IMediaFromFile>(_source); } else { _mMedia = _mFactory.CreateMedia <IMedia>(_source); } _mMedia.AddOptions(_arguments); _mMedia.Events.DurationChanged -= EventsDurationChanged; _mMedia.Events.StateChanged -= EventsStateChanged; _mMedia.Events.DurationChanged += EventsDurationChanged; _mMedia.Events.StateChanged += EventsStateChanged; _needsSetup = true; _mPlayer.Open(_mMedia); _mMedia.Parse(true); _framesReceived = 0; Duration = Time = 0; LastFrame = DateTime.MinValue; _mPlayer.Play(); //check if file source (isseekable in _mPlayer is not reliable) Seekable = false; try { var p = Path.GetFullPath(_mMedia.Input); Seekable = !String.IsNullOrEmpty(p); } catch (Exception) { Seekable = false; } } } }