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)
Slumpe
  • 65
  • 1
  • 1
  • 3
  • possible duplicate of [How to open an Excel file with Python to display its content?](http://stackoverflow.com/questions/21191494/how-to-open-an-excel-file-with-python-to-display-its-content) – wnnmaw Jan 23 '14 at 16:15
  • So, I don't know about Windows, but if you have Linux, or a virtual machine, you can leverage ffmpeg, http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs. – cjohnson318 Jan 23 '14 at 16:15

1 Answers1

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()
Adam Smith
  • 52,157
  • 12
  • 73
  • 112