6

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) 
2

1 Answer 1

9

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() 
Sign up to request clarification or add additional context in comments.

2 Comments

How to detect when the video has finished playing?
@user2993886 that's true! os.startfile is not available on non-Windows OS (per the docs)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.