Click here to Skip to main content
15,895,283 members
Articles / Web Development / HTML

nVLC

Rate me:
Please Sign up or sign in to vote.
4.94/5 (213 votes)
12 Feb 2018GPL316 min read 12.2M   69.9K   379  
A .NET API for the libVLC interface so the vast majority of VLC functionality could be utilized in managed applications
//    nVLC
//    
//    Author:  Roman Ginzburg
//
//    nVLC is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    nVLC is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU General Public License for more details.
//     
// ========================================================================

using Declarations;
using Declarations.Enums;
using Declarations.Players;
using Implementation.Exceptions;
using LibVlcWrapper;
using System;

namespace Implementation.Players
{
    internal class AudioPlayer : BasicPlayer, IAudioPlayer
    {
        private AudioRenderer m_render = null;

        public AudioPlayer(IntPtr hMediaLib)
            : base(hMediaLib)
        {

        }

        #region IAudioPlayer Members

        public int Volume
        {
            get
            {
                return LibVlcMethods.libvlc_audio_get_volume(m_hMediaPlayer);
            }
            set
            {
                LibVlcMethods.libvlc_audio_set_volume(m_hMediaPlayer, value);
            }
        }

        public bool Mute
        {
            get
            {
                return LibVlcMethods.libvlc_audio_get_mute(m_hMediaPlayer);
            }
            set
            {
                LibVlcMethods.libvlc_audio_set_mute(m_hMediaPlayer, value);
            }
        }

        public long Delay
        {
            get
            {
                return LibVlcMethods.libvlc_audio_get_delay(m_hMediaPlayer);
            }
            set
            {
                LibVlcMethods.libvlc_audio_set_delay(m_hMediaPlayer, value);
            }
        }

        public AudioChannelType Channel
        {
            get
            {
                return (AudioChannelType)LibVlcMethods.libvlc_audio_get_channel(m_hMediaPlayer);
            }
            set
            {
                LibVlcMethods.libvlc_audio_set_channel(m_hMediaPlayer, (libvlc_audio_output_channel_t)value);
            }
        }

        public void ToggleMute()
        {
            LibVlcMethods.libvlc_audio_toggle_mute(m_hMediaPlayer);
        }

        public IAudioRenderer CustomAudioRenderer
        {
            get 
            {
                if (m_render == null)
                {
                    m_render = new AudioRenderer(m_hMediaPlayer);
                }
                return m_render; 
            }
        }

        public AudioOutputDeviceType DeviceType
        {
            get
            {
                return (AudioOutputDeviceType)LibVlcMethods.libvlc_audio_output_get_device_type(m_hMediaPlayer);
            }
            set
            {
                LibVlcMethods.libvlc_audio_output_set_device_type(m_hMediaPlayer, (libvlc_audio_output_device_types_t)value);
            }
        }

        public void SetAudioOutputModuleAndDevice(AudioOutputModuleInfo module, AudioOutputDeviceInfo device)
        {
            if (module == null)
            {
                throw new ArgumentNullException("module");
            }

            if (device != null)
            {
                LibVlcMethods.libvlc_audio_output_device_set(m_hMediaPlayer, module.Name.ToUtf8(), device.Id.ToUtf8());
            }

            int res = LibVlcMethods.libvlc_audio_output_set(m_hMediaPlayer, module.Name.ToUtf8());
            if (res < 0)
            {
                throw new LibVlcException();
            }
        }

        #endregion

        public override void Play()
        {
            base.Play();
            if (m_render != null)
            {
                m_render.StartTimer();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (m_render != null)
            {
                m_render.Dispose();
                m_render = null;
            }

            base.Dispose(disposing);
        }

        public void SetEqualizer(Equalizer equalizer)
        {
            if (equalizer == null)
            {
                LibVlcMethods.libvlc_media_player_set_equalizer(m_hMediaPlayer, IntPtr.Zero);
                return;
            }

            LibVlcMethods.libvlc_media_player_set_equalizer(m_hMediaPlayer, equalizer.Handle);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions