Javi
Javi

Reputation: 483

Is there a way to pause and resume my Music Playlist between songs?

I am new with Python and I thought that it would be funny to play with music by creating a playlist. The code I wrote plays the mp3 files saved in my Music folder. Now I want to pause/resume while the script is running. Any tips and recommendations are well received.

import vlc
from mutagen.mp3 
import MP3
from glob import glob
import time

##Directory for Music Files########

audio_dir = '/path/to/Music'
files = glob (audio_dir + '/*.mp3')

####################################

for filename in files:

    current_song = vlc.MediaPlayer(filename)    
    audio_specs = MP3(filename)    
    current_song.play() 
    time.sleep(audio_specs.info.length)
    current_song.stop()

Upvotes: 0

Views: 260

Answers (1)

Amrsaeed
Amrsaeed

Reputation: 316

You can use Keyboard library to catch input from your keyboard and map that to the player.

import keyboard

keyboard.add_hotkey('p', current_song.pause, args=None)
keyboard.add_hotkey('r', current_song.play, args=None)

Upvotes: 1

Related Questions