2

I am build a movie search web application (using Django) that will basically take a folder of movie files that end with (.mp4, .avi, .mpg etc). A MySQL database get filled with information about the movie when I run the population script.

One of the columns are the file_path of the movie. I have a template that will show some basic information for the movie with a play button next to it.

When you click the play button, it will take it you to another page (using the slug of the movie title) and you'll see an embedded video.

PROBLEM: Is that the movie doesn't play when I click the play button the embed video. The file_path to the video is stored in the database which is then passed into the django template (so I can see the path).

Is there some way to let django access these movie file paths so that they may play in the browser? (or using the default linux media player).

P.S. The movie file paths are stored in the MySQL database.

Here are the models:

class Film(models.Model): title = models.CharField(max_length=128, default='Blank', help_text='film title') year = models.CharField(max_length=15, help_text='release year', blank=True, null=True) rated = models.CharField(max_length=15, default=1, null=True, blank=True) released = models.CharField(max_length=128, default='Blank', help_text='release date') runtime = models.CharField(max_length=15, default='Blank', help_text='film length') genre = models.ManyToManyField(Genre, default=1, blank=True) director = models.ManyToManyField(Director, default=1, blank=True) type = models.CharField(max_length=20, default='filmdb', help_text='series, movie etc') actor = models.ManyToManyField(Actor, blank=True, verbose_name='Actor/Actress') writer = models.ManyToManyField(Writer, blank=True, verbose_name='Writer') award = models.CharField(max_length=128, default='Blank', null=True,help_text='film awards') country = models.ManyToManyField(Country, default=1, blank=True) language = models.ManyToManyField(Language) plot = models.TextField(max_length=256, help_text="Film plot", null=True, blank=True) poster = models.URLField(max_length=256, help_text='link to poster image', blank=True, null=True) imdb_id = models.CharField(max_length=15, default=1, null=True, blank=True) imdb_rating = models.CharField(max_length=15, null=True, blank=True) meta_score = models.CharField(max_length=10, null=True,blank=True) file_path = models.CharField(max_length=255, null=True, blank=True, default='N/A') slug = models.SlugField(unique=True) def save(self, *args, **kwargs): self.slug = slugify(self.title) super(Film, self).save(*args, **kwargs) def __unicode__(self): return self.title + self.year 
5
  • Have you read: w3schools.com/html/html5_video.asp ? Commented Jun 17, 2015 at 17:29
  • yes, I was referring to that this morning <video width="320" height="240" autoplay> <source src="{{ movie }}" type="video/mp4"> Your browser does not support the video tag. </video> and that is how I included it in the page. The problem is the movie doesn't play. Do I need to server it from the static folder? but all the file paths are stored in the database. Commented Jun 17, 2015 at 17:36
  • Is movie a FileField? Please add your model to the question. Commented Jun 17, 2015 at 17:37
  • no, it's a CharField Commented Jun 17, 2015 at 17:38
  • Can you add your model code to the question? Commented Jun 17, 2015 at 17:39

2 Answers 2

2

Without knowing if the path is absolute or relative, you should be using:

<video width="320" height="240" autoplay> <source src="{{ movie.file_path }}" type="video/mp4"> Your browser does not support the video tag. </video> 

Except, I would be using a relative path, not an absolute path. These files have to be served by something like Apache, Nginx or Django's built-in server for development.

The paths to these files really should be relative to the directory their being served from. If you're uploading these files via Django admin for example, then they're being uploaded to the MEDIA_ROOT, and their .url attribute will be relative to that. E.g.:

/movie/top_gun.mp4 

For most sites, I typically put the MEDIA_ROOT under the STATIC_ROOT, so I can serve them easily in development or production.

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

10 Comments

"{{ movie.file_path }}" is what I also used in the source. The path is absolute ex. /home/user/Downloads/movie/top_gun.mp4
Is the Downloads directory being served by the staticfiles app in development? or ? Is it only failing locally? or on your production site?
The Downloads directory is not being served by the staticfiles app (using development server). There is no production site yet.
What is your STATICFILES_DIRS setting?
STATIC_PATH = os.path.join(BASE_DIR, 'static') STATICFILES_DIRS = ( STATIC_PATH, )
|
0

If it finds the path, then add .url at the end of your jinja like code in your template html and must be in a video tag, like below:

<video controls src="{{ Tutorials.attachments.url }}"></video> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.