简体   繁体   中英

How to pause/resume playback with complexaudio in python?

My program is playing music with simpleaudio in python. But I would like to use the complexaudio extension that should allow to pause/resume the music. But i can't find any documentation of how to use it in order to do that. I've only been able to install complexaudio, but can't find any example... Is there anybody who already used those functions? many thanks !!!

I had the same problem as you but solved it:)

So first i uninstalled simpleaudio lib: pip uninstall simpleaudio

Then i installed complexaudio lib: pip install complexaudio

Then i went to have a look in the Site-Packages folder and in shiny.py which is actually simpleaudio script i saw this:

class PlayObject(object):
    def __init__(self, play_id):
        self.play_id = play_id

    def pause(self):
        return _sa._pause(self.play_id)

    def resume(self):
        return _sa._resume(self.play_id)

    def stop(self):
        _sa._stop(self.play_id)

    def wait_done(self):
        while self.is_playing():
            sleep(0.05)

    def is_playing(self):
        return _sa._is_playing(self.play_id)

PS: This lib works only for wav files so you can use mp3 to wav online but will make huges wav files:'(

For the use of the complexaudio functions it's really simple:

import simpleaudio as sa
import time

wave_obj = sa.WaveObject.from_wave_file("zik.wav")
play_obj = wave_obj.play()

time.sleep(3)
play_obj.pause()
print("paused")
time.sleep(3)
play_obj.resume()
print("resumed")
time.sleep(3)
play_obj.stop()
print("stoped")

play_obj.wait_done()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM