def getstats(): """ Gather VLC statistics """ m = vlcplayer.get_media() stats = vlc.MediaStats() m.get_stats(stats) return stats
def toista(self, url, *param): self.videoPlayer.set_mrl(url, *param) self.videoPlayer.play() self.viimNahtyAika = time.time() self.valvoTimer.start() self.mediaStats = vlc.MediaStats() self.media = self.videoPlayer.get_media() self.valvoTimer.start() FormVideo.show() FormVideo.showMaximized()
def _on_state_change(self, vlc_event, state): if state == 'Playing': # Multicast streams don't really trigger the buffering callback very reliably. # So we check if the demuxer has processed any data yet before marking it as 'Playing' mstats = vlc.MediaStats() self.player.get_media().get_stats(mstats) if mstats.demux_read_bytes == 0: state = 'Buffering' self.state = state self.emit('media_state', self.state)
def get_current_playlist_position(self): """ Returns the integer of the position that the currently playing media file is in the playlist of items being played. """ media = self.vlc['player'].get_media() if media: stats = vlc.MediaStats() media.get_stats(stats) playlist_position = self.vlc['playlist'].index_of_item(media) return playlist_position return None
def get_media_player_status(self): """ Compile the media player status into a dictionary. """ media = self.vlc['player'].get_media() if media: stats = vlc.MediaStats() media.get_stats(stats) playlist_position = self.vlc['playlist'].index_of_item(media) try: label_id = self.playlist[playlist_position]['label']['id'] except TypeError: # No label ID for this playlist item label_id = None try: system_volume = str( alsaaudio.Mixer(alsaaudio.mixers()[0]).getvolume()[0] / 10) except alsaaudio.ALSAAudioError: system_volume = 0 media_player_status = { 'datetime': self.datetime_now(), 'playlist_id': int(XOS_PLAYLIST_ID), 'media_player_id': int(XOS_MEDIA_PLAYER_ID), 'label_id': label_id, 'playlist_position': playlist_position, 'playback_position': self.vlc['player'].get_position(), 'dropped_audio_frames': stats.lost_abuffers, 'dropped_video_frames': stats.lost_pictures, 'duration': self.vlc['player'].get_length(), 'player_volume': \ # Player value 0-256 str(self.vlc['player'].audio_get_volume() / 256 * 10), 'system_volume': \ # System value 0-100 system_volume, } else: # playlist is empty message = f'No playable items in playlist {int(XOS_PLAYLIST_ID)} '\ f'on mediaplayer {int(XOS_MEDIA_PLAYER_ID)}' media_player_status = { 'error': message, } return media_player_status
def menuInfo_(self, item): try: self.menuPause_(item) # display Python, vlc, libVLC, media info table p = self.player m = p.get_media() t = Table(' Name:bold', ' Value:200:Center:center', ' Alt:100') t.append(_Argv0, __version__, '20' + __version__) t.append('PyCocoa', _pycocoa_version, '20' + _pycocoa_version) t.append('Python', *_Python) t.append(*_macOS()) x = 'built-in' if self.window.screen.isBuiltIn else 'external' t.append('screen', x, str(self.window.screen.displayID)) t.separator() t.append('vlc.py', vlc.__version__, hex(vlc.hex_version())) b = ' '.join(vlc.build_date.split()[:5]) t.append('built', strftime('%x', strptime(b, '%c')), vlc.build_date) t.separator() t.append('libVLC', bytes2str(vlc.libvlc_get_version()), hex(vlc.libvlc_hex_version())) t.append('libVLC', *bytes2str(vlc.libvlc_get_compiler()).split(None, 1)) t.separator() f = mrl_unquote(bytes2str(m.get_mrl())) t.append('media', basename(f), f) if f.lower().startswith('file://'): z = getsize(f[7:]) t.append('size', z1000str(z), zSIstr(z)) t.append('state', str(p.get_state())) f = max(p.get_position(), 0) t.append('position/length', '%.2f%%' % (f * 100, ), _ms2str(p.get_length())) f = map(_ms2str, (p.get_time(), m.get_duration())) t.append('time/duration', *f) t.append('track/count', z1000str(p.video_get_track()), z1000str(p.video_get_track_count())) t.separator() f = p.get_fps() t.append('fps/mspf', '%.6f' % (f, ), '%.3f ms' % (_mspf(f), )) r = p.get_rate() t.append('rate', '%s%%' % (int(r * 100), ), r) w, h = p.video_get_size(0) t.append('video size', _ratio2str('x', w, h)) # num=0 r = _ratio2str(':', *aspect_ratio(w, h)) # p.video_get_aspect_ratio() t.append('aspect ratio', r, _ratio2str(':', *self.window.ratio)) t.append('scale', '%.3f' % (p.video_get_scale(), ), '%.3f' % (self.scale, )) t.separator() def VLCadjustr2(option): # get option value lo, _, hi = _Adjust3[option] f = self.player.video_get_adjust_float(option) p = max(0, (f - lo)) * 100.0 / (hi - lo) t = '%.2f %.1f%%' % (f, p) # return 2-tuple (value, percentage) as strings return t.replace('.0%', '%').replace('.00', '.0').split() t.append('brightness', *VLCadjustr2(_Adjust.Brightness)) t.append('contrast', *VLCadjustr2(_Adjust.Contrast)) t.append('gamma', *VLCadjustr2(_Adjust.Gamma)) t.append('hue', *VLCadjustr2(_Adjust.Hue)) t.append('saturation', *VLCadjustr2(_Adjust.Saturation)) t.separator() s = vlc.MediaStats() # re-use single MediaStats instance? if m.get_stats(s): def Kops2bpstr2(bitrate): # convert Ko/s to bits/sec # bitrates are conventionally in kilo-octets-per-sec return zSIstr(bitrate * 8000, B='bps', K=1000).split() t.append('media read', *zSIstr(s.read_bytes).split()) t.append('input bitrate', *Kops2bpstr2(s.input_bitrate)) if s.input_bitrate > 0: # XXX approximate caching, based # on <https://GitHub.com/oaubert/python-vlc/issues/61> b = s.read_bytes - s.demux_read_bytes t.append('input caching', _ms2str(b / s.input_bitrate), zSIstr(b)) t.append('demux read', *zSIstr(s.demux_read_bytes).split()) t.append('stream bitrate', *Kops2bpstr2(s.demux_bitrate)) t.append('video decoded', z1000str(s.decoded_video), 'blocks') t.append('video played', z1000str(s.displayed_pictures), 'frames') t.append('video lost', z1000str(s.lost_pictures), 'frames') t.append('audio decoded', z1000str(s.decoded_audio), 'blocks') t.append('audio played', z1000str(s.played_abuffers), 'buffers') t.append('audio lost', z1000str(s.lost_abuffers), 'buffers') t.display('Python, VLC & Media Information', width=500) except Exception as x: if self.raiser: raise printf('%s', x, nl=1, nt=1)
def __init__(self, media): threading.Thread.__init__(self) self.media = media self.stats = vlc.MediaStats() self.count = 0