1

I am using libvlc python binding to play a music file.my code is as follows:

import vlc
instance = vlc.Instance()

#Create a MediaPlayer with the default instance
player = instance.media_player_new()

#Load the media file
media = instance.media_new('01.DONT CARE.mp3')

#Add the media to the player
player.set_media(media)

try:
    player.play()
except Exception, e:
    raise e

The script executes successfully but I am unable to hear anything. If the code is executed line by line then it works correctly and I am able to hear the sound.Any idea on what might be wrong?

1
  • If you add a call to time.sleep() after player.play(), do you hear the sound? Commented Jan 19, 2016 at 13:52

1 Answer 1

4

I think the reason it is not being played is because player.play() is asynchronous. So when the script exits, it kills the process and stops the media straight away. Try add a time.sleep(10) and see does it play.

Note: Don't forget to import time at the top.

The reason that it would be working as you type it in line by line is because it isn't exiting the python program.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.