【问题标题】:Play sound using bytes that works on android使用适用于 android 的字节播放声音
【发布时间】:2021-05-17 21:52:30
【问题描述】:

我有一个来自套接字的字节数组,客户端(应用程序)接收这些字节,我需要一种在 android 上播放这些字节的方法。我已经测试了 PyAudio(在 linux 上正确安装时会产生奇迹。)但我不能在 android 上使用 PyAudio。 (我正在使用 Kivy 构建我的应用程序)

有没有一些工具可以在 android 上播放字节格式的音频?

【问题讨论】:

    标签: python audio kivy


    【解决方案1】:

    好吧,我建议使用默认的 android 音频播放器。您可以使用jinus 访问它。

    from jnius import autoclass
    MediaPlayer = autoclass('android.media.MediaPlayer')
    AudioManager = autoclass('android.media.AudioManager')
    
    self.sound = MediaPlayer()
    self.sound.setDataSource(yourDataSource) #you can provide any data source, if its on the devie then the file path, or its url if you are playing online
    self.sound.prepare()
    self.sound.setLooping(False) #you can set it to true if you want to loop
    self.sound.start()
    # You can also use the following according to your needs
    #self.sound.pause()
    #self.sound.stop()
    #self.sound.release()
    #self.sound.getCurrentPosition()
    #self.sound.getDuration()
    

    【讨论】:

    猜你喜欢
    • 2015-07-11
    • 1970-01-01
    • 2016-09-22
    • 2011-09-04
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    相关资源
    最近更新 更多