google-code-export / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

pyglet.media.Player broken on Python3 #533

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. import pyglet
2. player = pyglet.media.Player()

Paste in the traceback or error message:
Traceback (most recent call last):
  File "/usr/local/lib/python3.2/dist-packages/pyglet/__init__.py", line 334, in __getattr__
    return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'Player'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/pyglet/__init__.py", line 340, in __getattr__
    __import__(import_name)
  File "/usr/local/lib/python3.2/dist-packages/pyglet/media/__init__.py", line 1469, in <module>
    from . import avbin
  File "/usr/local/lib/python3.2/dist-packages/pyglet/media/avbin.py", line 563, in <module>
    _have_frame_rate = av.avbin_have_feature('frame_rate')
  File "/usr/local/lib/python3.2/dist-packages/pyglet/media/avbin.py", line 189, in f
    result = func(*args)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

Seen on Ubuntu 11.04; Stock Python 3.2; Build Pyglet from git-rev 4ce991e689f8
Ive all the libav*-dev Packages installed, Build the last Pyglet-release with 
python2 - and it works there

Original issue reported on code.google.com by t.steinr...@gmail.com on 13 Sep 2011 at 12:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi, I had a similar error messages with pyglet.resource.media('any.mp3')
Probably this is str/bytes problem on Python3.
Some avbin_functions accept ctypes.c_char_p, which is compatible only with 
bytes object.

Quick and dirty solution is adding following code to pyglet/media/avbin.py, 
between line 188 and 189

 args = (e.encode() if isinstance(e, str) else e for e in args)

This code encodes all str objects passed to avbin_function to utf-8 bytes 
objects.
Works fine even with non-ascii filenames on ArchLinux x86_64; CPython 3.2; 
Pyglet rev 625e1e191389

Sorry for my poor english.
Hidesato Ikeya

Original comment by bombomba...@gmail.com on 11 Nov 2011 at 1:01

GoogleCodeExporter commented 9 years ago
I made a patch using pyglet/compat.py
Works fine on ArchLinux x86_64; CPython 3.2; Pyglet rev 625e1e191389

Original comment by bombomba...@gmail.com on 12 Nov 2011 at 4:04

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for your patch, it's now applied in rev 62e91545b98e

Original comment by andreas....@gmail.com on 11 Mar 2012 at 3:07