Python论坛  - 讨论区

标题:[python-chinese] mplayer bug or python bug?

2007年02月07日 星期三 19:40

Marco marco在waven.com
星期三 二月 7 19:40:48 HKT 2007

The following code is my test program for control mplayer.
in movies/ there are about 20 movies, the code plays them in circle,
but mplayer will crash silently after a circle, the "sliently" means I
can handle popen2 without except, but no movie.

I have no idea about it...
Can you help me?

class SimplePlayer( myobject ):
    def __init__(self):
        self.debug('simple player init ready')
        self.is_open = False
        self.wfd = None
        self.rfd = None

    def play(self, file):
        if self.is_open:
            self.wfd.write('loadfile %s\n' %(file))
            self.wfd.flush()
        else:
            self.wfd, self.rfd = os.popen2('mplayer -loop 0 -slave
-quiet -ao null %s 2> /dev/null' %(file))
            self.is_open = True


##################
if __name__ == '__main__':
    player = SimplePlayer()
    all = os.listdir('movies/')
    print all
    while True:
        for current in all:
            print current
            player.play('movies/' + current)
            time.sleep(3)

-- 
LinuX Power

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年02月08日 星期四 09:03

amingsc amingsc在gmail.com
星期四 二月 8 09:03:23 HKT 2007


Marco 写道:
> The following code is my test program for control mplayer.
> in movies/ there are about 20 movies, the code plays them in circle,
> but mplayer will crash silently after a circle, the "sliently" means I
> can handle popen2 without except, but no movie.
>
> I have no idea about it...
> Can you help me?
>
> class SimplePlayer( myobject ):
>     def __init__(self):
>         self.debug('simple player init ready')
>         self.is_open = False
>         self.wfd = None
>         self.rfd = None
>
>     def play(self, file):
>         if self.is_open:
>             self.wfd.write('loadfile %s\n' %(file))
>             self.wfd.flush()
>         else:
>             self.wfd, self.rfd = os.popen2('mplayer -loop 0 -slave
> -quiet -ao null %s 2> /dev/null' %(file))
>             self.is_open = True
>
>
> ##################
> if __name__ == '__main__':
>     player = SimplePlayer()
>     all = os.listdir('movies/')
>     print all
>     while True:
>         for current in all:
>             print current
>             player.play('movies/' + current)
>             time.sleep(3)
>   
没看懂,既然是循环播放为什么不等待os.popen2开启的子进程退出后再播放下一 
个呢?上面在播放的过程中向stdin写入“loadfile %s\n' %(file)”是什么作用?
没用过popen2,想请教一下它返回的stdin有什么意义?thanku

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号