ponty / pyscreenshot

Python screenshot library, replacement for the Pillow ImageGrab module on Linux.
BSD 2-Clause "Simplified" License
499 stars 89 forks source link

grab make pygame play sound not working #73

Closed alibaltschun closed 4 years ago

alibaltschun commented 4 years ago

I have some work with PyGame for play mp3. but I can't play the mp3 after grab screen

file_A.py

from pygame import mixer
mixer.init()
def play(PATH, target):

    # play the sound
    print("play", target + ".mp3")
    mixer.music.load(PATH + target + ".mp3")
    mixer.music.play()

play("x","y")                   // its work if i call here

file_B.py

from .file_A import play
import pyscreenshot as ImageGrab

def main():

    play("x","y")                           // its working, but
    left = ImageGrab.grab(bbox=(1,2,3,4))  
    play("x","y")                           // after grab log printed that method call but sound not working

python 3.7.4 pygame 1.9.6 pyscreenshot 1.0.0

alibaltschun commented 4 years ago

i found the main problem, its not a bug. but the audio interupted coz all code in that method already executed and the method done before mixer play di audio

file_B.py

from .file_A import play
import pyscreenshot as ImageGrab
import time

def main():

    play("x1","y")                           // its working here, but
    left = ImageGrab.grab(bbox=(1,2,3,4))    // after grab
    play("x2","y")                           // log printed that method called but sound not working
    time.sleep(n)                            // wait the audio play