[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] pyg_mixer.music.load doesn't take non ascii chars



see also https://www.python.org/dev/peps/pep-0263/
i'd got a similar problem between windows, dos, and linux filesnames, ascii files.

i'd try your exacte copy "07-Boabdil, BulerÃas.ogg".
exact code is:

#!/usr/bin/env python
# -*- coding: utf8 -*-
Â
import os
Â
import pygame
from pygame.locals import *

pygame.init()
pygame.mixer.set_num_channels(3)
pygame.mixer.init()
Â
file_path = "07-Boabdil, BulerÃas.ogg"
print file_path
file_path = file_path.decode('utf8')

print file_path

pygame.mixer.music.load(open(file_path))
pygame.mixer.music.play(1)
pygame.mixer.music.set_volume(0.5)
Â

2015-02-14 11:46 GMT+01:00 Gino Ingras <ginoingras@xxxxxxxxx>:
you should learn about codecs strings inputs/output.
ensure you always work with the same, utf8.
most of python modules are based on, and python3 assume by default as in python2 you got

from __future__ import unicode_literals

see (in french, sorry) a good link:
http://sametmax.com/lencoding-en-python-une-bonne-fois-pour-toute/
Â

2015-02-14 11:21 GMT+01:00 Bo Jangeborg <bo@xxxxxxxxxxx>:
Greg Ewing skrev den 2015-02-14 02:00:

Bo Jangeborg wrote:
file_path = "07-Boabdil, BulerÃas.ogg"
fi = open(file_path, 'rb').read()
pygame.mixer.music.load(fi)

But that gets me the Error:
"File path 'OggS' contains null characters"

music.load() expects to be passed the name of a file,
not the contents of the file. Just do this:

file_path = "07-Boabdil, BulerÃas.ogg"
pygame.mixer.music.load(file_path)

The reason I tried the object passing was because just
passing the name didn't work. So I am looking for
a workaround. According to the documentation
one should be able to pass an object as a parameter
but I am not sure if I am doing it the right way.

pygame.mixer.music.load()
Load a music file for playback
load(filename) -> None
load(object) -> None
This will load a music filename/file object and prepare it for playback.