fix resuming video playback after background audio only mode.
This commit is contained in:
@@ -1315,6 +1315,66 @@ pub fn update_lockscreen_metadata(meta: &LockscreenMetadata) -> Result<(), Strin
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the base position offset (seconds) on the lockscreen MediaSession.
|
||||
///
|
||||
/// Calls `JellyTauPlaybackService.setPositionOffset(double)`. No-op if the
|
||||
/// service isn't running yet, so it's safe to call unconditionally.
|
||||
pub fn set_position_offset(offset_seconds: f64) -> Result<(), String> {
|
||||
let vm = JAVA_VM.get().ok_or("JavaVM not initialized")?;
|
||||
let mut env = vm.attach_current_thread().map_err(|e| e.to_string())?;
|
||||
|
||||
let context = APP_CONTEXT.get().ok_or("Context not initialized")?;
|
||||
|
||||
let class_loader = env
|
||||
.call_method(context, "getClassLoader", "()Ljava/lang/ClassLoader;", &[])
|
||||
.map_err(|e| format!("Failed to get ClassLoader: {}", e))?
|
||||
.l()
|
||||
.map_err(|e| format!("Failed to convert ClassLoader: {}", e))?;
|
||||
|
||||
let service_class_name = env
|
||||
.new_string("com.dtourolle.jellytau.player.JellyTauPlaybackService")
|
||||
.map_err(|e| format!("Failed to create class name string: {}", e))?;
|
||||
|
||||
let service_class_obj = env
|
||||
.call_method(
|
||||
&class_loader,
|
||||
"loadClass",
|
||||
"(Ljava/lang/String;)Ljava/lang/Class;",
|
||||
&[JValue::Object(&service_class_name.into())],
|
||||
)
|
||||
.map_err(|e| format!("Failed to load JellyTauPlaybackService class: {}", e))?
|
||||
.l()
|
||||
.map_err(|e| format!("Failed to convert to Class: {}", e))?;
|
||||
|
||||
let service_class = JClass::from(service_class_obj);
|
||||
|
||||
let service_obj = env
|
||||
.call_static_method(
|
||||
&service_class,
|
||||
"getInstance",
|
||||
"()Lcom/dtourolle/jellytau/player/JellyTauPlaybackService;",
|
||||
&[],
|
||||
)
|
||||
.map_err(|e| format!("Failed to get service instance: {}", e))?
|
||||
.l()
|
||||
.map_err(|e| format!("Failed to convert to object: {}", e))?;
|
||||
|
||||
// Service not running yet - nothing to offset.
|
||||
if service_obj.is_null() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
env.call_method(
|
||||
&service_obj,
|
||||
"setPositionOffset",
|
||||
"(D)V",
|
||||
&[JValue::Double(offset_seconds)],
|
||||
)
|
||||
.map_err(|e| format!("Failed to set position offset: {}", e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Stub implementations for non-Android platforms
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub fn enable_remote_volume(_initial_volume: i32) -> Result<(), String> {
|
||||
|
||||
@@ -80,6 +80,22 @@ pub fn update_lockscreen_metadata(_meta: &LockscreenMetadata) -> Result<(), Stri
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the base offset (seconds) added to positions reported to the Android
|
||||
/// lockscreen scrubber. Used by the background-audio handoff: the audio stream
|
||||
/// starts at the handoff point (StartTimeTicks), so ExoPlayer's position is
|
||||
/// relative and must be shifted back to absolute to match the full duration.
|
||||
/// Pass 0.0 to clear on exit. No-op off Android.
|
||||
pub fn set_lockscreen_position_offset(_offset_seconds: f64) -> Result<(), String> {
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
return android::set_position_offset(_offset_seconds);
|
||||
}
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
use crate::utils::lock::MutexSafe;
|
||||
use log::{debug, error, warn};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
Reference in New Issue
Block a user