Hardware Reference
In-Depth Information
6. Leave a blank line and then type the following lines:
player = vlc.MediaPlayer()
medialist = vlc.MediaList(files)
mlplayer = vlc.MediaListPlayer()
mlplayer.set_media_player(player)
mlplayer.set_media_list(medialist)
his part of the code sets up how you will be using the vlc library. he details
aren't important, but you set up a MediaListPlayer , which is a Player that
plays a MediaList (rather than just having one track queued at a time).
7. Later in the project, you are going to add buttons to play, pause and skip between
tracks, so here you need to add a while loop to read the input of buttons, and
use keyboard buttons 1, 2, 3, 4 to test that it works. Begin your while loop
with this code:
while True:
button = input(“Hit a button “)
if button == “1”:
print(“Pressed play button”)
if mlplayer.is_playing():
mlplayer.pause()
else:
mlplayer.play()
elif button == “2”:
print(“Pressed stop button”)
mlplayer.stop()
he 1 key on your keyboard will act as the play/pause button, while the 2 key will
act as the stop button. Inside the while loop, you have used some conditionals.
Be careful with your indentation here!
he irst level of the condition depends on which button is pressed: if 1 is
pressed or else if ( elif ) 2 is pressed. Inside each button press is a second condi-
tion. If button 1 is pressed when a track is playing, the media player will pause. If
nothing is playing, the media player will play a random track. If button 2 is
pressed, the media player stops the track after printing Pressed stop but-
ton to the screen.
8. When the stop button is pushed, you want to make it so that when you hit play
again the tracks have been reshuled. To do that, you sort the list of iles again
using random , and then replace the MediaList using that reshuled list of
iles. Directly underneath the last line of the previous code, and at the same level
of indentation, type these lines:
random.shuffle(files)
medialist = vlc.MediaList(files)
mlplayer.set_media_list(medialist)
Search WWH ::




Custom Search