当前位置: 首页>>代码示例>>Python>>正文


Python BytesIO.tell方法代码示例

本文整理汇总了Python中pyglet.compat.BytesIO.tell方法的典型用法代码示例。如果您正苦于以下问题:Python BytesIO.tell方法的具体用法?Python BytesIO.tell怎么用?Python BytesIO.tell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyglet.compat.BytesIO的用法示例。


在下文中一共展示了BytesIO.tell方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: StaticMemorySource

# 需要导入模块: from pyglet.compat import BytesIO [as 别名]
# 或者: from pyglet.compat.BytesIO import tell [as 别名]
class StaticMemorySource(StaticSource):

    """Helper class for default implementation of `StaticSource`.  Do not use
    directly."""

    def __init__(self, data, audio_format):
        """Construct a memory source over the given data buffer.
        """
        self._file = BytesIO(data)
        self._max_offset = len(data)
        self.audio_format = audio_format
        self._duration = len(data) / float(audio_format.bytes_per_second)

    def seek(self, timestamp):
        offset = int(timestamp * self.audio_format.bytes_per_second)

        # Align to sample
        if self.audio_format.bytes_per_sample == 2:
            offset &= 0xfffffffe
        elif self.audio_format.bytes_per_sample == 4:
            offset &= 0xfffffffc

        self._file.seek(offset)

    def get_audio_data(self, bytes_):
        offset = self._file.tell()
        timestamp = float(offset) / self.audio_format.bytes_per_second

        # Align to sample size
        if self.audio_format.bytes_per_sample == 2:
            bytes_ &= 0xfffffffe
        elif self.audio_format.bytes_per_sample == 4:
            bytes_ &= 0xfffffffc

        data = self._file.read(bytes_)
        if not len(data):
            return None

        duration = float(len(data)) / self.audio_format.bytes_per_second
        return AudioData(data, len(data), timestamp, duration, list())
开发者ID:bitcraft,项目名称:pyglet,代码行数:42,代码来源:__init__.py


注:本文中的pyglet.compat.BytesIO.tell方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。