Fixed pause which broke in the switch to mpv. Fixed bookmarks being lost when switching books using the recent bookmarks.
This commit is contained in:
@@ -62,13 +62,55 @@ class MpvPlayer:
|
||||
print(f"Warning: Could not initialize mpv: {e}")
|
||||
self.isInitialized = False
|
||||
|
||||
def play_wav_data(self, wavData):
|
||||
def play_wav_data(self, wavData, playbackSpeed=None):
|
||||
"""
|
||||
This method is no longer used for TTS playback.
|
||||
TTS playback is now handled directly by BookReader using subprocess.
|
||||
Play WAV data directly from memory (for TTS)
|
||||
|
||||
Args:
|
||||
wavData: WAV file data as bytes
|
||||
playbackSpeed: Playback speed (0.5 to 2.0), uses current speed if None
|
||||
|
||||
Returns:
|
||||
True if playback started successfully
|
||||
"""
|
||||
print("Warning: MpvPlayer.play_wav_data is deprecated and should not be called.")
|
||||
return False
|
||||
if not self.isInitialized or not self.player:
|
||||
return False
|
||||
|
||||
import tempfile
|
||||
tempFile = None
|
||||
try:
|
||||
# Create a temporary file for the WAV data
|
||||
# python-mpv needs a file path, it can't play from memory directly
|
||||
tempFile = tempfile.NamedTemporaryFile(suffix='.wav', delete=False)
|
||||
tempFile.write(wavData)
|
||||
tempFile.close()
|
||||
|
||||
# Use current playback speed if not specified
|
||||
if playbackSpeed is None:
|
||||
playbackSpeed = self.playbackSpeed
|
||||
|
||||
# Load and play the temp file
|
||||
success = self.load_audio_file(tempFile.name, playbackSpeed=playbackSpeed)
|
||||
if success:
|
||||
success = self.play_audio_file()
|
||||
|
||||
# Clean up temp file after a delay (mpv needs time to load it)
|
||||
if tempFile:
|
||||
import threading
|
||||
import time
|
||||
def cleanup_temp_file(filepath):
|
||||
time.sleep(5) # Wait for mpv to fully load the file
|
||||
try:
|
||||
os.unlink(filepath)
|
||||
except:
|
||||
pass
|
||||
threading.Thread(target=cleanup_temp_file, args=(tempFile.name,), daemon=True).start()
|
||||
|
||||
return success
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error playing WAV data: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def pause(self):
|
||||
|
||||
Reference in New Issue
Block a user