Auto-play support

This commit is contained in:
2025-10-11 22:53:52 +09:00
parent 280a1e54be
commit 26db66e501

View File

@@ -56,6 +56,10 @@ public class MainActivity extends AppCompatActivity {
// File picker launcher
private ActivityResultLauncher<Intent> filePicker;
// Auto-play support
private String autoPlayFilePath = null;
private boolean isInitializationComplete = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -75,6 +79,78 @@ public class MainActivity extends AppCompatActivity {
}
updateUI();
// Check if file path was provided via Intent
handleIntentAutoPlay();
}
/**
* Handle auto-play from Intent parameter
* Supports: adb shell am start -n com.vavcore.player/.MainActivity --es filepath "/path/to/video.webm"
*/
private void handleIntentAutoPlay() {
Intent intent = getIntent();
if (intent != null && intent.hasExtra("filepath")) {
String filePath = intent.getStringExtra("filepath");
if (filePath != null && filePath.endsWith(".webm")) {
android.util.Log.i(TAG, "Auto-play requested for: " + filePath);
autoPlayFilePath = filePath;
// Wait for Vulkan initialization to complete before loading video
vulkanVideoView.post(() -> {
// Additional delay to ensure full initialization
new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(() -> {
performAutoPlay();
}, 500); // 500ms delay for complete initialization
});
} else {
showError("Invalid file path. Only .webm files are supported.");
}
}
}
/**
* Perform auto-play after initialization is complete
*/
private void performAutoPlay() {
if (autoPlayFilePath == null) {
return;
}
android.util.Log.i(TAG, "Starting auto-play for: " + autoPlayFilePath);
// Extract filename from path
String fileName = autoPlayFilePath.substring(autoPlayFilePath.lastIndexOf('/') + 1);
// Load video
boolean success = vulkanVideoView.loadVideo(autoPlayFilePath);
if (success) {
VideoInfo info = vulkanVideoView.getVideoInfo();
if (info != null) {
statusText.setText(String.format("Auto-playing: %s (%dx%d, %.1f fps)",
fileName, info.width, info.height, info.frameRate));
vulkanVideoView.setVideoSize(info.width, info.height);
// Set video duration for progress tracking
videoDurationUs = info.durationUs;
// Update overlay with video info
videoPlayerOverlay.setVideoTitle(fileName);
videoPlayerOverlay.updateProgress(0, videoDurationUs);
videoPlayerOverlay.show(); // Show overlay
// Auto-start playback after a short delay
new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(() -> {
playVideo();
android.util.Log.i(TAG, "Auto-play started successfully");
}, 200); // 200ms delay before starting playback
}
} else {
showError("Failed to auto-play video: " + fileName);
}
// Clear auto-play file path
autoPlayFilePath = null;
}
private void initializeComponents() {