|
发表于 2017-12-19 23:46:58
|
显示全部楼层
看到还没有翻译,于是自己动手翻译了一下以飨大家,希望能有点用途。不过由于我水平和知识面有限,错误和纰漏的地方在所难免,希望大家批评指正。
pygame.mixer
pygame用来加载和播放声音的模块
pygame.mixer.init — 初始化mixer 模块
pygame.mixer.pre_init — 预设mixer.init()函数的参数
pygame.mixer.quit — 取消对mixer的初始化
pygame.mixer.get_init — 测试mixer是否已经初始化
pygame.mixer.stop — 关闭所有音频的播放
pygame.mixer.pause — 暂停所有音频的播放
pygame.mixer.unpause — 取消所有音频播放的暂停
pygame.mixer.fadeout — 所有声音停止前音量逐步降低
pygame.mixer.set_num_channels — 设置播放频道的总数
pygame.mixer.get_num_channels — 获取播放频道的总数
pygame.mixer.set_reserved — 保留频道不被自动占用
pygame.mixer.find_channel — 查找一个未使用的频道
pygame.mixer.get_busy — 测试任何声音是否被混合
pygame.mixer.Sound — 从文件或缓冲对象创建一个新的Sound对象
pygame.mixer.Channel — 创建一个频道对象以控制播放
This module contains classes for loading Sound objects and controlling playback. The mixer module is optional and depends on SDL_mixer. Your program should test that pygame.mixer is available and intialized before using it.
本模块包含加载声音对象和控制播放的类。mixer模块是可选的且基于SDL_mixer。你的程序在使用pygame.mixer前需测试该模块是否存在并对其进行初始化。
The mixer module has a limited number of channels for playback of sounds. Usually programs tell pygame to start playing audio and it selects an available channel automatically. The default is 8 simultaneous channels, but complex programs can get more precise control over the number of channels and their use.
mixer模块播放声音时使用的频道数是有限的。通常程序告知pygame开始播放音频并自动选取一个可用的频道。尽管默认的同时播放的通道数为8,但复杂的程序可以更精确的控制频道的数目及其用途。
All sound playback is mixed in background threads. When you begin to play a Sound object, it will return immediately while the sound continues to play. A single Sound object can also be actively played back multiple times.
所有的声音播放在后台进程中混合。打你开始播放一个Sound对象时,该对象会立即返回而声音继续播放。单个Sound对象也可以播放多次。
The mixer also has a special streaming channel. This is for music playback and is accessed through the pygame.mixer.music module.
混合器还有一个特殊的流频道,用于音乐的播放并且通过pygame.mixer.music模块可以获取。
The mixer module must be initialized like other pygame modules, but it has some extra conditions. The pygame.mixer.init() function takes several optional arguments to control the playback rate and sample size. Pygame will default to reasonable values, but pygame cannot perform Sound resampling, so the mixer should be initialized to match the values of your audio resources.
虽然mixer模块也必须像其他模块一样先进行初始化,但还需要额外的条件。pygame.mixer.init()函数使用几个可选的参数来控制播放速率和样本尺寸。Pygame选取了适当的数值作为其默认值,但pygame不能对声音重采样,因而mixer需要初始化为适合你的音频源的数值。
NOTE: Not to get less laggy sound, use a smaller buffer size. The default is set to reduce the chance of scratchy sounds on some computers. You can change the default buffer by calling pygame.mixer.pre_init()preset the mixer init arguments before pygame.mixer.init()initialize the mixer module or pygame.init()initialize all imported pygame modules is called. For example: pygame.mixer.pre_init(44100,-16,2, 1024) The default size was changed from 1024 to 3072 in pygame 1.8.
注:使用较小的buffer数值来减小声音延迟。默认值可以减少某些电脑上沙沙声发生的机会。你可以通过在调用pygame.mixer.init()或pygame.init()前调用pygame.mixer.pre_init()来改变默认的buffer值。例如,pygame.mixer.pre_init(44100,-16,2, 1024)。在pygame 1.8中默认buffer参数的数值可从1024变化到3072。
pygame.mixer.init()
initialize the mixer module
init(frequency=22050, size=-16, channels=2, buffer=4096) -> None
Initialize the mixer module for Sound loading and playback. The default arguments can be overridden to provide specific audio mixing. Keyword arguments are accepted. For backward compatibility where an argument is set zero the default value is used (possible changed by a pre_init call).
初始化mixer模块
init(frequency=22050, size=-16, channels=2, buffer=4096) -> None
初始化用于加载声音对象和控制播放的mixer模块。为了对特定音频进行混合,默认参数可被改写。也可以接受关键字参数。为便于向后兼容,使用0作为参数的默认值(可以通过调用pre_init函数来改变)。
The size argument represents how many bits are used for each audio sample. If the value is negative then signed sample values will be used. Positive values mean unsigned audio samples will be used. An invalid value raises an exception.
The channels argument is used to specify whether to use mono or stereo. 1 for mono and 2 for stereo. No other values are supported (negative values are treated as 1, values greater than 2 as 2).
Size参数用于指定使用的是单音还是立体音。1代表单音,2代表立体音。不支持其他数值(负数会被当做1来处理,而大于2的数值将视为2)。
The buffer argument controls the number of internal samples used in the sound mixer. The default value should work for most cases. It can be lowered to reduce latency, but sound dropout may occur. It can be raised to larger values to ensure playback never skips, but it will impose latency on sound playback. The buffer size must be a power of two (if not it is rounded up to the next nearest power of 2).
Buffer参数控制声音混合器使用的内部样本的数量。默认值对大部分情况都是有效的。虽然减小其数值可以降低延迟,但可能会导致声音丢失。较大的数值尽管可以保证播放不会跳过,但会对声音播放造成延迟。
Some platforms require the pygame.mixer module to be initialized after the display modules have initialized. The top level pygame.init() takes care of this automatically, but cannot pass any arguments to the mixer init. To solve this, mixer has a function pygame.mixer.pre_init() to set the proper defaults before the toplevel init is used.
It is safe to call this more than once, but after the mixer is initialized you cannot change the playback arguments without first calling pygame.mixer.quit().
一些平台要求pygame.mixer在display模块初始化后必须进行初始化。虽然顶层的pygame.init()会自动进行这些操作,但它不能传递任何参数到mixer init。为解决这个问题,在顶层初始化后可以使用函数pygame.mixer.pre_init()来设置合适的默认值。
尽管可以不止一次的调用这个函数,但是如果不事先调用pygame.mixer.quit()的情况下一旦混合器被初始化了你就无法改变播放参数。
pygame.mixer.pre_init()
preset the mixer init arguments
pre_init(frequency=22050, size=-16, channels=2, buffersize=4096) -> None
Call pre_init to change the defaults used when the real pygame.mixer.init() is called. Keyword arguments are accepted. The best way to set custom mixer playback values is to call pygame.mixer.pre_init() before calling the top level pygame.init(). For backward compatibility argument values of zero is replaced with the startup defaults.
预设混合器init函数的参数
pre_init(frequency=22050, size=-16, channels=2, buffersize=4096) -> None
当pygame.mixer.init()被调用时调用pre_init函数可以改变默认值。接受关键字参数。设置自定义播放数值的最佳方式是在调用顶层pygame.init()之前调用pygame.mixer.pre_init()。为便于向后兼容,0值的参数被启动时的默认值代替。
pygame.mixer.quit()
uninitialize the mixer
quit() -> None
This will uninitialize pygame.mixerpygame module for loading and playing sounds. All playback will stop and any loaded Sound objects may not be compatible with the mixer if it is reinitialized later.
取消对mixer的初始化
quit() -> None
该函数将取消对pygame.mixer的初始化。所有的播放将会停止且任何已加载的Sound对象后续如果重新初始化时会与混合器不兼容
pygame.mixer.get_init()
test if the mixer is initialized
get_init() -> (frequency, format, channels)
If the mixer is initialized, this returns the playback arguments it is using. If the mixer has not been initialized this returns None
测试混合器是否已初始化
get_init() -> (frequency, format, channels)
如果混合器初始化了,将会返回使用的播放参数。如果混合器还没有初始化,将会返回None。
pygame.mixer.stop()
stop playback of all sound channels
stop() -> None
This will stop all playback of all active mixer channels.
停止所有音频的播放
stop() -> None
将会停止所有激活的混合器频道的所有播放。
pygame.mixer.pause()
temporarily stop playback of all sound channels
pause() -> None
This will temporarily stop all playback on the active mixer channels. The playback can later be resumed with pygame.mixer.unpause()
暂停所有音频的播放
pause() -> None
将会暂停所有在激活的混合器频道上的播放。之后可以通过pygame.mixer.unpause()来恢复播放。
pygame.mixer.unpause()
resume paused playback of sound channels
unpause() -> None
This will resume all active sound channels after they have been paused.
恢复音频的播放
unpause() -> None
在暂停音频后可将所有激活的音频恢复播放。
pygame.mixer.fadeout()
fade out the volume on all sounds before stopping
fadeout(time) -> None
This will fade out the volume on all active channels over the time argument in milliseconds. After the sound is muted the playback will stop.
所有声音停止前音量逐步降低
fadeout(time) -> None
以毫秒为单位随时间逐步降低所有激活的频道的音量。声音变弱后播放将会停止。
pygame.mixer.set_num_channels()
set the total number of playback channels
set_num_channels(count) -> None
Sets the number of available channels for the mixer. The default value is 8. The value can be increased or decreased. If the value is decreased, sounds playing on the truncated channels are stopped.
设置播放频道的总数
set_num_channels(count) -> None
设置混合器可选频道的数目。默认值为8且可被增大或减小。如果数值减小了,截断通道上播放的声音停止播放。
pygame.mixer.get_num_channels()
get the total number of playback channels
get_num_channels() -> count
Returns the number of currently active playback channels.
获取播放频道的总数
get_num_channels() -> count
返回当前活跃的播放频道的数目。
pygame.mixer.set_reserved()
reserve channels from being automatically used
set_reserved(count) -> None
The mixer can reserve any number of channels that will not be automatically selected for playback by Sounds. If sounds are currently playing on the reserved channels they will not be stopped.
This allows the application to reserve a specific number of channels for important sounds that must not be dropped or have a guaranteed channel to play on.
保留频道不被自动占用
set_reserved(count) -> None
混合器可以保留任意数量的频道以便不被Sound自动选用。当前在保留频道上播放的sounds不好被停止。
这样保证了应用为那些确实不可以被丢弃的重要声音保留一定数量的频道或者确保有一频道可供播放。
pygame.mixer.find_channel()
find an unused channel
find_channel(force=False) -> Channel
This will find and return an inactive Channel object. If there are no inactive Channels this function will return None. If there are no inactive channels and the force argument is True, this will find the Channel with the longest running Sound and return it.
If the mixer has reserved channels from pygame.mixer.set_reserved() then those channels will not be returned here.
查找一个为被使用的频道
find_channel(force=False) -> Channel
查找并返回一个未被激活的Channel对象。如果没有未被激活的Channel对象将返回None。如果没有未被激活的Channel对象且force参数为True,将查找带有最长运行Sound的Channel并将其返回。
如果混合器通过pygame.mixer.set_reserved()设置了保留频道,那么这些Channel不会被返回。
pygame.mixer.get_busy()
test if any sound is being mixed
get_busy() -> bool
Returns True if the mixer is busy mixing any channels. If the mixer is idle then this return False.
测试任意声音是否被混合
get_busy() -> bool
如果混合器正忙于混合频道则返回True。如果混合器空闲则返回False。
pygame.mixer.Sound
Create a new Sound object from a file or buffer object
从文件或buffer对象创建一个新的Sound对象
Sound(filename) -> Sound
Sound(file=filename) -> Sound
Sound(buffer) -> Sound
Sound(buffer=buffer) -> Sound
Sound(object) -> Sound
Sound(file=object) -> Sound
Sound(array=object) -> Sound
pygame.mixer.Sound.play — 开始播放声音
pygame.mixer.Sound.stop — 停止播放声音
pygame.mixer.Sound.fadeout — 在声音渐弱后停止播放
pygame.mixer.Sound.set_volume — 设置Sound对象播放的音量
pygame.mixer.Sound.get_volume — 获取播放的音量
pygame.mixer.Sound.get_num_channels — 记录Sound播放的次数
pygame.mixer.Sound.get_length — 获取Sound的长度
pygame.mixer.Sound.get_raw — 返回Sound样本的字节串副本
Load a new sound buffer from a filename, a python file object or a readable buffer object. Limited resampling will be performed to help the sample match the initialize arguments for the mixer. A Unicode string can only be a file pathname. A Python 2.x string or a Python 3.x bytes object can be either a pathname or a buffer object. Use the ‘file’ or ‘buffer’ keywords to avoid ambiguity; otherwise Sound may guess wrong. If the array keyword is used, the object is expected to export a version 3, C level array interface or, for Python 2.6 or later, a new buffer interface (The object is checked for a buffer interface first.)
The Sound object represents actual sound sample data. Methods that change the state of the Sound object will the all instances of the Sound playback. A Sound object also exports an array interface, and, for Python 2.6 or later, a new buffer interface.
The Sound can be loaded from an OGG audio file or from an uncompressed WAV.
Note: The buffer will be copied internally, no data will be shared between it and the Sound object.
从文件名、python文件对象或者是可读的buffer对象加载一个新的声音缓冲。为便于样本匹配混合器的初始参数会进行有限的重采样。Unicode字符串仅可作为文件路径名。Python 2.x string或者 Python 3.x bytes对象即可作为路径名又可作为一个buffer对象。使用’file’或者‘buffer’关键字来避免歧义,否则Sound会判断失误。如果使用’array’关键字,该对象被视为导出一个Python 3的C层面的array界面,或者对于Python 2.6及之后版本则视为一个新的buffer界面。
Sound可从一个OGG音频文件或者未压缩的WAV文件加载。
注:buffer的拷贝发生在内部,不会与Sound对象共享数据。
For now buffer and array support is consistent with sndarray.make_sound for Numeric arrays, in that sample sign and byte order are ignored. This will change, either by correctly handling sign and byte order, or by raising an exception when different. Also, source samples are truncated to fit the audio sample size. This will not change.
pygame.mixer.Sound(buffer) is new in pygame 1.8 pygame.mixer.SoundCreate a new Sound object from a file or buffer object keyword arguments and array interface support new in pygame 1.9.2
目前,buffer和array与sndarray.make_sound对于数值阵列是一致的,都会忽略样本的标记和字节顺序。既可以通过适当处理标记和字节顺序,也可以通过当不同时则抛出异常的方法来改变。同时,源样本会被截断以便适合音频样本尺寸。这一点不会改变。
pygame.mixer.Sound(buffer)是pygame 1.8新增的内容。Pygame.mixer.Sound关键字参数和array界面支持为pygame 1.9.2新增的内容。
play()
begin sound playback
play(loops=0, maxtime=0, fade_ms=0) -> Channel
Begin playback of the Sound (i.e., on the computer’s speakers) on an available Channel. This will forcibly select a Channel, so playback may cut off a currently playing sound if necessary.
开始播放声音
play(loops=0, maxtime=0, fade_ms=0) -> Channel
开始在一个可用的频道上播放声音(例如在一台电脑的喇叭上)。这将强制选取一个Channel,因而播放时如果必要时会砍掉一个当前正在播放的声音。
The loops argument controls how many times the sample will be repeated after being played the first time. A value of 5 means that the sound will be played once, then repeated five times, and so is played a total of six times. The default value (zero) means the Sound is not repeated, and so is only played once. If loops is set to -1 the Sound will loop indefinitely (though you can still call stop() to stop it).
The maxtime argument can be used to stop playback after a given number of milliseconds.
The fade_ms argument will make the sound start playing at 0 volume and fade up to full volume over the time given. The sample may end before the fade-in is complete.
This returns the Channel object for the channel that was selected.
loops参数控制样本从第一次播放开始算起重复的次数。数值5意味着这个声音要被播放一次,然后重复5次,因而总计播放了6次。默认值(0)意味着Sound对象不被重复,亦即仅播放一次。如果将loops设置为-1,那么Sound对象会无限制地循环播放(不过你仍旧可以调用stop()来停止它)。
stop()
stop sound playback
stop() -> None
This will stop the playback of this Sound on any active Channels.
停止声音的播放
stop() -> None
将会停止该Sound对象在任何激活的Channel上的播放。
fadeout()
stop sound playback after fading out
fadeout(time) -> None
This will stop playback of the sound after fading it out over the time argument in milliseconds. The Sound will fade and stop on all actively playing channels.
在声音渐弱后停止播放
fadeout(time) -> None
将会在声音渐弱后以毫秒为time参数的单位来停止播放。Sound将会渐弱并在所有活跃播放的channel上停止。
set_volume()
set the playback volume for this Sound
set_volume(value) -> None
This will set the playback volume (loudness) for this Sound. This will immediately affect the Sound if it is playing. It will also affect any future playback of this Sound. The argument is a value from 0.0 to 1.0.
设置该Sound播放的音量
set_volume(value) -> None
将会设置该Sound播放的音量(响度)。如果声音在播放,这将立马见效。这也将会影响之后该Sound的任何播放。value参数的值从0.0到1.0。
get_volume()
get the playback volume
get_volume() -> value
Return a value from 0.0 to 1.0 representing the volume for this Sound.
获取播放的音量
get_volume() -> value
返回一个从0.0到1.0代表该Sound音量值的数值。
get_num_channels()
count how many times this Sound is playing
get_num_channels() -> count
Return the number of active channels this sound is playing on.
记录Sound播放的次数
get_num_channels() -> count
返回供该声音播放的活跃频道数目。
get_length()
get the length of the Sound
get_length() -> seconds
Return the length of this Sound in seconds.
获取Sound的长度
get_length() -> seconds
返回以秒计时的该Sound的长度。
get_raw()
return a bytestring copy of the Sound samples.
get_raw() -> bytes
Return a copy of the Sound object buffer as a bytes (for Python 3.x) or str (for Python 2.x) object.
New in pygame 1.9.2.
返回Sound样本的字节串副本
get_raw() -> bytes
返回该Sound对象缓冲作为一个bytes对象(Python 3.x) 或者是str对象(Python 2.x)的副本。
pygame.mixer.Channel
Create a Channel object for controlling playback
创建一个Channel对象来控制播放
Channel(id) -> Channel
pygame.mixer.Channel.play — 在指定Channel上播放声音
pygame.mixer.Channel.stop — 停止一个频道上的播放
pygame.mixer.Channel.pause — 暂停一个频道上的播放
pygame.mixer.Channel.unpause — 取消暂停一个频道上的播放
pygame.mixer.Channel.fadeout — 频道渐弱后停止播放
pygame.mixer.Channel.set_volume — 设置一个正在播放的频道的音量
pygame.mixer.Channel.get_volume — 获取一个正在播放的频道的音量
pygame.mixer.Channel.get_busy — 检查该频道是否活跃
pygame.mixer.Channel.get_sound — 获取当前正在播放的Sound
pygame.mixer.Channel.queue — 使一个Sound对象紧接当前排队
pygame.mixer.Channel.get_queue — 返回任何在排队中的Sound
pygame.mixer.Channel.set_endevent — 当播放停止时使频道引发一个事件
pygame.mixer.Channel.get_endevent — 当播放停止时使频道获取一个事件
Return a Channel object for one of the current channels. The id must be a value from 0 to the value of pygame.mixer.get_num_channels().
The Channel object can be used to get fine control over the playback of Sounds. A channel can only playback a single Sound at time. Using channels is entirely optional since pygame can manage them by default.
返回当前频道中的一个Channel对象。频道id必须是一个从0到pygame.mixer.get_num_channels()的数值。
Channel对象可用于很好的控制Sound的播放。一个频道一次只能播放一个单一Sound。使用频道完全是可选的因为pygame默认情况下可以管理它们。
play()
play a Sound on a specific Channel
play(Sound, loops=0, maxtime=0, fade_ms=0) -> None
This will begin playback of a Sound on a specific Channel. If the Channel is currently playing any other Sound it will be stopped.
The loops argument has the same meaning as in Sound.play(): it is the number of times to repeat the sound after the first time. If it is 3, the sound will be played 4 times (the first time, then three more). If loops is -1 then the playback will repeat indefinitely.
播放某一特定频道上的一个Sound
play(Sound, loops=0, maxtime=0, fade_ms=0) -> None
将会在一个指定的Channel上开始播放一个Sound。如果该Channel当前正在播放任何其他Sound,那个声音会被终止。
Loops参数与Sound.play()有着相同的含义:它是开始第一次播放之后重复的次数。如果是3,声音会播放4遍(先1遍,然后再3遍)。如果loops为-1则会无限制播放下去。
As in Sound.play(), the maxtime argument can be used to stop playback of the Sound after a given number of milliseconds.
As in Sound.play(), the fade_ms argument can be used fade in the sound.
正如Sound.play(),maxtime参数可用来使该Sound在播放了给定毫秒数后停止。同样,fade_ms参数可用来渐弱声音。
stop()
stop playback on a Channel
停止一个频道上的播放
stop() -> None
Stop sound playback on a channel. After playback is stopped the channel becomes available for new Sounds to play on it.
停止在一个频道上声音的播放。当一个频道的播放被停止后又可被用于新的Sound的播放。
pause()
temporarily stop playback of a channel
暂停一个频道上的播放
pause() -> None
Temporarily stop the playback of sound on a channel. It can be resumed at a later time with Channel.unpause()
暂停一个频道上声音的播放。之后可用Channel.unpause()恢复播放。
unpause()
resume pause playback of a channel
取消暂停一个频道上的播放
unpause() -> None
Resume the playback on a paused channel.
取消暂停一个频道上的播放。
fadeout()
stop playback after fading channel out
频道渐弱后停止播放
fadeout(time) -> None
Stop playback of a channel after fading out the sound over the given time argument in milliseconds.
在声音渐弱time参数指定的毫秒数之后停止频道的播放。
set_volume()
set the volume of a playing channel
设置一个正在播放的频道的音量
set_volume(value) -> None
set_volume(left, right) -> None
Set the volume (loudness) of a playing sound. When a channel starts to play its volume value is reset. This only affects the current sound. The value argument is between 0.0 and 1.0.
设置播放声音的音量(响度)。当一个频道开始播放时其音量值被重置。这仅对当前声音有影响。value参数介于0.0与1.0之间。
If one argument is passed, it will be the volume of both speakers. If two arguments are passed and the mixer is in stereo mode, the first argument will be the volume of the left speaker and the second will be the volume of the right speaker. (If the second argument is None, the first argument will be the volume of both speakers.)
如果仅传递一个参数,将被视为两个喇叭共同的音量。如果传递两个参数且混合器处于立体音模式,则第一个参数为左扬声器的音量、第二个为右扬声器的音量。(如果第二个参数为None,第一个参数则为两个喇叭共同的音量。)
If the channel is playing a Sound on which set_volume() has also been called, both calls are taken into account. For example:
sound = pygame.mixer.Sound("s.wav")
channel = s.play() # Sound plays at full volume by default
sound.set_volume(0.9) # Now plays at 90% of full volume.
sound.set_volume(0.6) # Now plays at 60% (previous value replaced).
channel.set_volume(0.5) # Now plays at 30% (0.6 * 0.5).
get_volume()
get the volume of the playing channel
获取一个正在播放的频道的音量
get_volume() -> value
Return the volume of the channel for the current playing sound. This does not take into account stereo separation used by Channel.set_volume(). The Sound object also has its own volume which is mixed with the channel.
返回当前正在播放的声音所在频道的音量。该函数不考虑Channel.set_volume()所用的立体分离。Sound对象也有自己的音量用于与频道相混。
get_busy()
check if the channel is active
检查该频道是否活跃
get_busy() -> bool
Returns true if the channel is actively mixing sound. If the channel is idle this returns False.
如果该频道当前在混合声音则返回True。如果频道空闲则返回False。
get_sound()
get the currently playing Sound
获取当前正在播放的Sound
get_sound() -> Sound
Return the actual Sound object currently playing on this channel. If the channel is idle None is returned.
返回在该频道上当前正在播放的实际的Sound对象。如果频道空闲则返回None。
queue()
queue a Sound object to follow the current
使一个Sound对象紧接当前排队
queue(Sound) -> None
When a Sound is queued on a Channel, it will begin playing immediately after the current Sound is finished. Each channel can only have a single Sound queued at a time. The queued Sound will only play if the current playback finished automatically. It is cleared on any other call to Channel.stop() or Channel.play().
If there is no sound actively playing on the Channel then the Sound will begin playing immediately.
当一个Sound在一个频道排队时,在当前声音结束后它将立即开始播放。每个频道每次只能有一个单一Sound排队。该排队的Sound只有在当前播放自动完成后才会播放。该Sound在当调用Channel.stop()或者Channel.play()时会被清理。
get_queue()
return any Sound that is queued
返回任何在排队中的Sound
get_queue() -> Sound
If a Sound is already queued on this channel it will be returned. Once the queued sound begins playback it will no longer be on the queue.
如果一个Sound已经在该频道排队则将其返回。一旦该排队的声音开始播放它就不再在队列之中。
set_endevent()
have the channel send an event when playback stops
当播放停止时使频道引发一个事件
set_endevent() -> None
set_endevent(type) -> None
When an endevent is set for a channel, it will send an event to the pygame queue every time a sound finishes playing on that channel (not just the first time). Use pygame.event.get() to retrieve the endevent once it’s sent.
Note that if you called Sound.play(n) or Channel.play(sound,n), the end event is sent only once: after the sound has been played “n+1” times (see the documentation of Sound.play).
If Channel.stop() or Channel.play() is called while the sound was still playing, the event will be posted immediately.
The type argument will be the event id sent to the queue. This can be any valid event type, but a good choice would be a value between pygame.locals.USEREVENT and pygame.locals.NUMEVENTS. If no type argument is given then the Channel will stop sending endevents.
当一个频道被设置了一个endevent时,则每当一个声音在那个频道上完成播放时(不只是第一次)就会向pygame queue发送一个事件。一旦被发送了,可使用pygame.event.get()获取该endevet。
注意如果你调用了Sound.play(n) 或 Channel.play(sound,n),该endevent仅会发送一次:仅在声音已被播放了’n+1’次后(见Sound.play)。
如果当声音仍旧在播放时调用了Channel.stop() 或 Channel.play(),那么该事件会被立即引发。
type参数为被发送到队列的事件的 id,可为任何有效的事件类型,不过最好选择介于pygame.locals.USEREVENT和pygame.locals.NUMEVENTS的数值。如果不给出tpye参数,那么该频道会停止发送endevent。
get_endevent()
get the event a channel sends when playback stops
当播放停止时使频道获取一个事件
get_endevent() -> type
Returns the event type to be sent every time the Channel finishes playback of a Sound. If there is no endevent the function returns pygame.NOEVENT.
返回每当该频道完成一个Sound的播放后将要被发送的事件的类型。如果没有endevent,那么该函数返回pygame.NOEVENT事件。
---- End pygame.mixer ----- |
|