Play .mp4 Using Python And Check If/while It Is Still Playing
I'm using Windows 64 bit. I have tried several libraries. Couldnt' get pygame to work, couldnt' get pymedia to install on python 2.7. Eventually got mplayer for python. Installed
Solution 1:
It's a little awkward to do this, due to the streaming nature of this implementation, and the lack of documentation.
However, this is how you do it:
p = 'C:\\mymusic.mp4'
v = VideoPlayback_MPlayer.FromPath(p)
v.playAsync()
while v.isPlaying:
time.sleep(0.1)
Where you have a video player class like this:
classVideoPlayback_MPlayer:
def__init__(self, path):
self.path = path
defplayAsync(self):
import mplayer #pip install mplayer.py and also setup choco install mplayer myself via http://downloads.sourceforge.net/project/mplayer-win32/MPlayer%20and%20MEncoder/r37451%2Bg531b0a3/MPlayer-x86_64-r37451%2Bg531b0a3.7z?r=http%3A%2F%2Foss.netfarm.it%2Fmplayer%2F&ts=1442363467&use_mirror=tcpdiag
self.isPlaying = True
EOFDetectionArgs = "-msglevel global=6"
self.player = mplayer.Player(args=EOFDetectionArgs.split(), stderr=None, autospawn=True)
self.player.stdout.connect(self._EOFDetector)
self.player.loadfile(self.path)
self.player.pause() # someone says online this kicks in the audio http://stackoverflow.com/questions/16385225/play-mp4-using-python-and-check-if-while-it-is-still-playing def_EOFDetector(self, stream):
if stream.startswith('EOF code:'):
self.isPlaying = False @propertydefdone(self):
returnnot self.isPlaying
defplay(self):
self.playAsync()
while self.isPlaying:
time.sleep(0.00001)
@staticmethoddefFromPath(path):
return VideoPlayback_MPlayer(path)
Post a Comment for "Play .mp4 Using Python And Check If/while It Is Still Playing"