Python vlc.Instance() Examples

The following are 11 code examples for showing how to use vlc.Instance(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module vlc , or try the search function .

Example 1
Project: PiPod   Author: BramRausch   File: playback.py    License: MIT License 5 votes vote down vote up
def __init__(self):
        self.vlcInstance = vlc.Instance()
        self.player = self.vlcInstance.media_player_new()
        self.alsa = alsaaudio.Mixer(alsaaudio.mixers()[0])
        self.alsa.setvolume(self.volume) 
Example 2
Project: kickoff-player   Author: jonian   File: vlcbox.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
    Gtk.Box.__init__(self, *args, **kwargs)

    self.canvas = Gtk.DrawingArea()
    self.pack_start(self.canvas, True, True, 0)

    self.instance = vlc.Instance()
    self.canvas.connect('realize', self.on_canvas_realized)
    self.canvas.connect('draw', self.on_canvas_draw)

    self.player = self.instance.media_player_new()
    self.player.video_set_scale(0)
    self.player.video_set_aspect_ratio('16:9')
    self.player.video_set_deinterlace('on')
    self.player.video_set_mouse_input(False)
    self.player.video_set_key_input(False)

    add_widget_class(self, 'player-video') 
Example 3
Project: platypush   Author: BlackLight   File: vlc.py    License: MIT License 5 votes vote down vote up
def _init_vlc(self, resource):
        import vlc
        self._reset_state()

        for k, v in self._env.items():
            os.environ[k] = v

        self._instance = vlc.Instance(*self._args)
        self._player = self._instance.media_player_new(resource)

        for evt in self._watched_event_types():
            self._player.event_manager().event_attach(
                eventtype=evt, callback=self._event_callback()) 
Example 4
Project: pympress   Author: Cimbali   File: vlc_backend.py    License: GNU General Public License v2.0 5 votes vote down vote up
def setup_backend(cls, vlc_opts = ['--no-video-title-show']):
        """ Prepare/check the VLC backend.

        Args:
            vlc_opts (`list`): the arguments for starting vlc

        Returns:
            `str`: the version of VLC used by the backend
        """
        if IS_WINDOWS and vlc.plugin_path:
            # let python find the DLLs
            os.environ['PATH'] = vlc.plugin_path + ';' + os.environ['PATH']

        VlcOverlay._instance = vlc.Instance(vlc_opts)
        return 'VLC {}'.format(vlc.libvlc_get_version().decode('ascii')) 
Example 5
Project: wonambi   Author: wonambi-python   File: video.py    License: GNU General Public License v3.0 5 votes vote down vote up
def create_video(self):
        """Create video widget."""

        self.instance = vlc.Instance()

        video_widget = QFrame()
        self.mediaplayer = self.instance.media_player_new()
        if system() == 'Linux':
            self.mediaplayer.set_xwindow(video_widget.winId())
        elif system() == 'Windows':
            self.mediaplayer.set_hwnd(video_widget.winId())
        elif system() == 'darwin':  # to test
            self.mediaplayer.set_nsobject(video_widget.winId())
        else:
            lg.warning('unsupported system for video widget')
            return

        self.medialistplayer = vlc.MediaListPlayer()
        self.medialistplayer.set_media_player(self.mediaplayer)
        event_manager = self.medialistplayer.event_manager()
        event_manager.event_attach(vlc.EventType.MediaListPlayerNextItemSet,
                                   self.next_video)

        self.idx_button = QPushButton()
        self.idx_button.setText('Start')
        self.idx_button.clicked.connect(self.start_stop_video)

        layout = QVBoxLayout()
        layout.addWidget(video_widget)
        layout.addWidget(self.idx_button)
        self.setLayout(layout) 
Example 6
Project: castero   Author: xgi   File: vlcplayer.py    License: MIT License 5 votes vote down vote up
def check_dependencies():
        """Checks whether dependencies are met for playing a player.

        Overrides method from Player; see documentation in that class.
        """
        try:
            import vlc
            i = vlc.Instance()
            vlc.libvlc_release(i)
        except (ImportError, NameError, OSError, AttributeError):
            raise PlayerDependencyError(
                "Dependency VLC not found, which is required for playing"
                " media files"
            ) 
Example 7
Project: castero   Author: xgi   File: vlcplayer.py    License: MIT License 5 votes vote down vote up
def _create_player(self) -> None:
        """Creates the player object while making sure it is a valid file.

        Overrides method from Player; see documentation in that class.
        """
        vlc_instance = self.vlc.Instance("--no-video --quiet")

        self._player = vlc_instance.media_player_new()
        self._media = vlc_instance.media_new(self._path)
        self._media.parse()  # may output some junk into the console
        self._player.set_media(self._media)

        self._duration = self._media.get_duration() 
Example 8
Project: GassistPi   Author: shivasiddharth   File: mediaplayer.py    License: GNU General Public License v3.0 5 votes vote down vote up
def play_audio_file(self,fname):
        Instance=vlc.Instance()
        player=Instance.media_player_new()
        player.set_mrl(fname)
        player.play() 
Example 9
Project: AlexaPi   Author: alexa-pi   File: vlchandler.py    License: MIT License 5 votes vote down vote up
def on_setup(self):

		parametersCommon = [
			# '--alsa-audio-device=mono'
			# '--file-logger'
			# '--logfile=vlc-log.txt'
		]

		parametersSpeech = parametersCommon

		if not platform.system() == 'Windows':

			if self.__config['sound']['output']:
				parametersSpeech.append('--aout=' + self.__config['sound']['output'])

				if self.__config['sound']['output_device']:
					parametersSpeech.append('--alsa-audio-device=' + self.__config['sound']['output_device'])

		self.vlc_instance = vlc.Instance(*parametersSpeech)
		self.player = self.vlc_instance.media_player_new()

		self.media_vlc_instance = self.vlc_instance
		self.media_player = self.player

		if not platform.system() == 'Windows':

			if self.__config['sound']['media_output']:
				parametersMedia = parametersCommon
				parametersMedia.append('--aout=' + self.__config['sound']['media_output'])

				if self.__config['sound']['media_output_device']:
					parametersMedia.append('--alsa-audio-device=' + self.__config['sound']['media_output_device'])

				self.media_vlc_instance = vlc.Instance(*parametersMedia)
				self.media_player = self.media_vlc_instance.media_player_new()

		if self.__config['sound']['default_volume']:
			self.volume = self.__config['sound']['default_volume']

		if self.__config['sound']['media_default_volume']:
			self.media_volume = self.__config['sound']['media_default_volume'] 
Example 10
Project: Python_Master_Courses   Author: makelove   File: examples_tkvlc.py    License: GNU General Public License v3.0 4 votes vote down vote up
def OnOpen(self):
        """Pop up a new dialow window to choose a file, then play the selected file.
        """
        # if a file is already running, then stop it.
        self.OnStop()

        # Create a file dialog opened in the current home directory, where
        # you can display all kind of files, having as title "Choose a file".
        p = pathlib.Path(os.path.expanduser("~"))
        fullname =  askopenfilename(initialdir = p, title = "choose your file",filetypes = (("all files","*.*"),("mp4 files","*.mp4")))
        if os.path.isfile(fullname):
            dirname  = os.path.dirname(fullname)
            filename = os.path.basename(fullname)
            # Creation
            self.Media = self.Instance.media_new(str(os.path.join(dirname, filename)))
            self.player.set_media(self.Media)
            # Report the title of the file chosen
            #title = self.player.get_title()
            #  if an error was encountred while retriving the title, then use
            #  filename
            #if title == -1:
            #    title = filename
            #self.SetTitle("%s - tkVLCplayer" % title)

            # set the window id where to render VLC's video output
            if platform.system() == 'Windows':
                self.player.set_hwnd(self.GetHandle())
            else:
                self.player.set_xwindow(self.GetHandle()) # this line messes up windows
            # FIXME: this should be made cross-platform
            self.OnPlay()

            # set the volume slider to the current volume
            #self.volslider.SetValue(self.player.audio_get_volume() / 2)
            self.volslider.set(self.player.audio_get_volume()) 
Example 11
Project: GassistPi   Author: shivasiddharth   File: mediaplayer.py    License: GNU General Public License v3.0 3 votes vote down vote up
def __init__(self):
        self.libvlc_Instance=vlc.Instance('--verbose 0')
        self.libvlc_player = self.libvlc_Instance.media_player_new()
        # self.libvlc_list_player = self.libvlc_Instance.media_list_player_new()
        # self.libvlc_Media_list = self.libvlc_Instance.media_list_new()
        # self.libvlc_list_player.set_media_player(self.libvlc_player)
        # self.libvlc_list_player.set_media_list(self.libvlc_Media_list)
        # self.libvlc_player_event_manager= self.libvlc_player.event_manager()