2021-11-27 22:05:48 +01:00
|
|
|
import vlc
|
|
|
|
|
2021-12-15 22:47:28 +01:00
|
|
|
all_events = (
|
|
|
|
vlc.EventType.MediaDiscovererEnded,
|
|
|
|
vlc.EventType.MediaDiscovererStarted,
|
|
|
|
vlc.EventType.MediaDurationChanged,
|
|
|
|
vlc.EventType.MediaFreed,
|
|
|
|
vlc.EventType.MediaListEndReached,
|
|
|
|
vlc.EventType.MediaListItemAdded,
|
|
|
|
vlc.EventType.MediaListItemDeleted,
|
|
|
|
vlc.EventType.MediaListPlayerNextItemSet,
|
|
|
|
vlc.EventType.MediaListPlayerPlayed,
|
|
|
|
vlc.EventType.MediaListPlayerStopped,
|
|
|
|
vlc.EventType.MediaListViewItemAdded,
|
|
|
|
vlc.EventType.MediaListViewItemDeleted,
|
|
|
|
vlc.EventType.MediaListViewWillAddItem,
|
|
|
|
vlc.EventType.MediaListViewWillDeleteItem,
|
|
|
|
vlc.EventType.MediaListWillAddItem,
|
|
|
|
vlc.EventType.MediaListWillDeleteItem,
|
|
|
|
vlc.EventType.MediaMetaChanged,
|
|
|
|
vlc.EventType.MediaParsedChanged,
|
|
|
|
vlc.EventType.MediaPlayerAudioDevice,
|
|
|
|
vlc.EventType.MediaPlayerAudioVolume,
|
|
|
|
vlc.EventType.MediaPlayerBackward,
|
|
|
|
vlc.EventType.MediaPlayerBuffering,
|
|
|
|
vlc.EventType.MediaPlayerChapterChanged,
|
|
|
|
vlc.EventType.MediaPlayerCorked,
|
|
|
|
vlc.EventType.MediaPlayerESAdded,
|
|
|
|
vlc.EventType.MediaPlayerESDeleted,
|
|
|
|
vlc.EventType.MediaPlayerESSelected,
|
|
|
|
vlc.EventType.MediaPlayerEncounteredError,
|
|
|
|
vlc.EventType.MediaPlayerEndReached,
|
|
|
|
vlc.EventType.MediaPlayerForward,
|
|
|
|
#vlc.EventType.MediaPlayerLengthChanged,
|
|
|
|
vlc.EventType.MediaPlayerMediaChanged,
|
|
|
|
vlc.EventType.MediaPlayerMuted,
|
|
|
|
vlc.EventType.MediaPlayerNothingSpecial,
|
|
|
|
vlc.EventType.MediaPlayerOpening,
|
|
|
|
vlc.EventType.MediaPlayerPausableChanged,
|
|
|
|
vlc.EventType.MediaPlayerPaused,
|
|
|
|
vlc.EventType.MediaPlayerPlaying,
|
|
|
|
#vlc.EventType.MediaPlayerPositionChanged,
|
|
|
|
vlc.EventType.MediaPlayerScrambledChanged,
|
|
|
|
vlc.EventType.MediaPlayerSeekableChanged,
|
|
|
|
vlc.EventType.MediaPlayerSnapshotTaken,
|
|
|
|
vlc.EventType.MediaPlayerStopped,
|
|
|
|
#vlc.EventType.MediaPlayerTimeChanged,
|
|
|
|
vlc.EventType.MediaPlayerTitleChanged,
|
|
|
|
vlc.EventType.MediaPlayerUncorked,
|
|
|
|
vlc.EventType.MediaPlayerUnmuted,
|
|
|
|
vlc.EventType.MediaPlayerVout,
|
|
|
|
vlc.EventType.MediaStateChanged,
|
|
|
|
vlc.EventType.MediaSubItemAdded,
|
|
|
|
vlc.EventType.MediaSubItemTreeAdded,
|
|
|
|
vlc.EventType.RendererDiscovererItemAdded,
|
|
|
|
vlc.EventType.RendererDiscovererItemDeleted,
|
|
|
|
vlc.EventType.VlmMediaAdded,
|
|
|
|
vlc.EventType.VlmMediaChanged,
|
|
|
|
vlc.EventType.VlmMediaInstanceStarted,
|
|
|
|
vlc.EventType.VlmMediaInstanceStatusEnd,
|
|
|
|
vlc.EventType.VlmMediaInstanceStatusError,
|
|
|
|
vlc.EventType.VlmMediaInstanceStatusInit,
|
|
|
|
vlc.EventType.VlmMediaInstanceStatusOpening,
|
|
|
|
vlc.EventType.VlmMediaInstanceStatusPause,
|
|
|
|
vlc.EventType.VlmMediaInstanceStatusPlaying,
|
|
|
|
vlc.EventType.VlmMediaInstanceStopped,
|
|
|
|
vlc.EventType.VlmMediaRemoved,
|
|
|
|
)
|
|
|
|
|
2021-11-27 22:05:48 +01:00
|
|
|
|
|
|
|
class AudioPlayer:
|
|
|
|
def __init__(self):
|
|
|
|
self.instance = vlc.Instance()
|
2021-12-15 22:47:28 +01:00
|
|
|
self.media_list_player = self.instance.media_list_player_new()
|
|
|
|
self.media_player = self.media_list_player.get_media_player()
|
|
|
|
|
|
|
|
evm = self.media_player.event_manager()
|
|
|
|
evm.event_attach(vlc.EventType.MediaPlayerEndReached, self._callback)
|
|
|
|
|
|
|
|
self.on_playlist_end_callback = None
|
|
|
|
|
|
|
|
def create_playlist(self, files):
|
|
|
|
result = vlc.MediaList()
|
|
|
|
for e in files:
|
|
|
|
result.add_media(self.instance.media_new(e))
|
|
|
|
return result
|
|
|
|
|
|
|
|
def set_playlist(self, media_list):
|
|
|
|
self.media_list_player.set_media_list(media_list)
|
2021-11-27 22:05:48 +01:00
|
|
|
|
2021-12-15 22:47:28 +01:00
|
|
|
def next(self):
|
|
|
|
self.media_list_player.next()
|
|
|
|
|
|
|
|
def previous(self):
|
|
|
|
self.media_list_player.previous()
|
2021-11-27 22:05:48 +01:00
|
|
|
|
|
|
|
def play(self):
|
2021-12-15 22:47:28 +01:00
|
|
|
self.media_list_player.play()
|
|
|
|
|
|
|
|
def play_from_start(self):
|
|
|
|
self.media_list_player.play_item_at_index(0)
|
|
|
|
|
|
|
|
def is_playing(self):
|
|
|
|
return self.media_list_player.is_playing()
|
2021-11-27 22:05:48 +01:00
|
|
|
|
|
|
|
def pause(self):
|
2021-12-15 22:47:28 +01:00
|
|
|
self.media_list_player.pause()
|
|
|
|
|
|
|
|
def _callback(self, event, *args, **kwargs):
|
|
|
|
if event.type == vlc.EventType.MediaPlayerEndReached:
|
|
|
|
print("End reached")
|
|
|
|
if self.on_playlist_end_callback:
|
|
|
|
self.on_playlist_end_callback()
|
|
|
|
#print("Callback from VLC", event, args, kwargs)
|
|
|
|
#print(event.meta_type, event.obj, event.type)
|