I was trying to make a script that would play a movie using the default windows application but when I try to run this I get the error: coercing to Unicode: need string or buffer, function found
How should I proceed with this?
import os
print 'Push "enter" to play movie'
raw_input()
def filename():
filename = movie.mp4
os.system("start " + filename)
open(filename)
If you just want to play an mp4 video, then this opencv program will help you to do that. You can change the name of the window as you like. If video file is in another directory, then give the patch of the video in the format 'Drive://x/x/xx.mp4'. 'ret' value shows whether the video file is read or not, frame wise.
The problem you're having is that you likely have a variable named movie
, and when you do filename = movie.mp4
it's setting assigning the movie
's function mp4
to the variable filename
. In any case, I don't think there's a reason to do this.
def play_movie(path):
from os import startfile
startfile(path)
That's literally all you need for your "Play" function. If I were you, I'd wrap it in a class, something like:
class Video(object):
def __init__(self,path):
self.path = path
def play(self):
from os import startfile
startfile(self.path)
class Movie_MP4(Video):
type = "MP4"
movie = Movie_MP4(r"C:\My Documents\My Videos\Heres_a_file.mp4")
if raw_input("Press enter to play, anything else to exit") == '':
movie.play()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With