0

Consider the following minimal working example using mpylayer:

import mpylayer

mp = mpylayer.MPlayerControl()

files = ['/tmp/video1.mp4','/tmp/video2.mp4']
for i in range (0,2):
    mp.loadfile(files[i])

This should play all of the video1.mp4 and after that it should open video2.mp4 and play this. However there are two problems:

  1. It doesn't play all of the video1.mp4 it just opens it for a second and then closes it.
  2. After closing video2.mp4 there is a delay of a few seconds until it begins playing video2.mp4

So how can I fix both problems?

Edit:

To fix the first problem I tried to use time.sleep(mp.length) i.e.

import mpylayer
import time

mp = mpylayer.MPlayerControl()

files = ['/tmp/video1.mp4','/tmp/video2.mp4']
for i in range (0,2):
    mp.loadfile(files[i])
    time.sleep(mp.length)

This works for the case that I don't pause the video, seek forward or backward or close it. So there must be a better solution.

student
  • 1,636
  • 3
  • 29
  • 53
  • Is loadfile() a blocking call? If it isn't, then that might explain the behavior you're seeing. – dckrooney May 30 '12 at 19:56
  • @dcrooney I am a very beginner in python and don't even know what a blocking call is. I linked the source code of mpylayer in my question above, perhaps you may have a look on it and see whether it is a blocking call or not – student May 31 '12 at 18:36

4 Answers4

1

I'm guessing that mp.loadfile() is asynchronous, meaning that your program will not stop and wait for your video to finish playing before continuing its execution. This would likely explain why your first video opens briefly, before the second video loads.

dckrooney
  • 3,041
  • 3
  • 22
  • 28
0

I don't know if this is a clever solution but it seems to work for both problems at least at the first sight:

import mpylayer
import time

mp = mpylayer.MPlayerControl()

files = ['/tmp/video1.mp4','/tmp/video2.mp4']
for i in range (0,2):
    mp.loadfile(files[i])
    l = mp.length
    while(mp.time_pos < l -1):
        time.sleep(1)

Edit:

import mpylayer
import time

mp = mpylayer.MPlayerControl()

files = ['/tmp/test1.mp4','/tmp/test2.mp4']


for i in range (0,len(files)):
    mp.loadfile(files[i])
    #mp.fullscreen=1
    while(mp.length == None):{} #Prevents that mp.length is None
    l = mp.length
    while(mp.time_pos != None and mp.time_pos < l):
        pos = mp.time_pos

Here is the delay smaller, but one gets a problem when seeking forward. Then mp.time_pos becomes None and the loop exits.

If someone has a suggestion to make it better, please let me know.

student
  • 1,636
  • 3
  • 29
  • 53
0

Why don't you add a dummy input line. The program won't continue until you press enter (I haven't coded Python for a while) but

import mpylayer
import time

mp = mpylayer.MPlayerControl()

files = ['/tmp/video1.mp4','/tmp/video2.mp4']
for i in range (0,2):
    mp.loadfile(files[i])
    dummy = input() // When user presses any button, you continue
user929404
  • 2,153
  • 1
  • 22
  • 27
  • I don't want to pause the video. I want that it smoothly goes from the first to the second video without any delay (for example if you cut one video into two parts and play those parts in my app, you should **not** notice any difference to playing the whole video alone) – student Jul 05 '13 at 17:57
0

You can use mfind an easy playlist maker for mplayer

Play all files from "locate" or "find" output and or all media files in a folder with mplayer. Inspired form "Play all files in folder" in "The KMPlayer" and "Everything" fast search and merge this feature.