235 lines
7.6 KiB
C#
235 lines
7.6 KiB
C#
using Godot;
|
|
|
|
public partial class Main : Control
|
|
{
|
|
// UI 요소들
|
|
private Label _statusLabel;
|
|
private Control _vavCorePlayer;
|
|
private Button _loadButton;
|
|
private Button _playButton;
|
|
private Button _pauseButton;
|
|
private Button _stopButton;
|
|
|
|
// VavCore Player 인스턴스
|
|
private VavCorePlayer _vavCorePlayerNode;
|
|
|
|
public override void _Ready()
|
|
{
|
|
GD.Print("VavCore Demo: Initializing...");
|
|
|
|
// UI 요소 참조 가져오기
|
|
_statusLabel = GetNode<Label>("VBoxContainer/StatusLabel");
|
|
_vavCorePlayer = GetNode<Control>("VBoxContainer/VideoContainer/VavCorePlayer");
|
|
_loadButton = GetNode<Button>("VBoxContainer/ControlPanel/LoadButton");
|
|
_playButton = GetNode<Button>("VBoxContainer/ControlPanel/PlayButton");
|
|
_pauseButton = GetNode<Button>("VBoxContainer/ControlPanel/PauseButton");
|
|
_stopButton = GetNode<Button>("VBoxContainer/ControlPanel/StopButton");
|
|
|
|
// 초기 상태 설정
|
|
_playButton.Disabled = true;
|
|
_pauseButton.Disabled = true;
|
|
_stopButton.Disabled = true;
|
|
|
|
UpdateStatus("Ready - VavCore Extension Demo");
|
|
|
|
// VavCore Extension 로드 확인
|
|
CheckVavCoreExtension();
|
|
}
|
|
|
|
private void CheckVavCoreExtension()
|
|
{
|
|
// VavCore Extension이 로드되었는지 확인
|
|
// 실제 VavCore 노드를 생성해보기
|
|
try
|
|
{
|
|
GD.Print("=== Checking for VavCore Extension ===");
|
|
|
|
// VideoContainer Panel 배경을 투명하게 설정
|
|
var videoContainer = GetNode<Panel>("VBoxContainer/VideoContainer");
|
|
|
|
// Panel의 기본 StyleBox를 제거하여 투명하게 만들기
|
|
var emptyStyleBox = new StyleBoxEmpty();
|
|
videoContainer.AddThemeStyleboxOverride("panel", emptyStyleBox);
|
|
|
|
GD.Print("VideoContainer panel made transparent");
|
|
|
|
// VavCorePlayer 노드 생성 및 추가
|
|
GD.Print("Creating VavCorePlayer instance...");
|
|
_vavCorePlayerNode = new VavCorePlayer();
|
|
GD.Print("VavCorePlayer instance created successfully");
|
|
|
|
_vavCorePlayerNode.Name = "VavCorePlayerNode";
|
|
GD.Print("Adding VavCorePlayer to scene...");
|
|
_vavCorePlayer.AddChild(_vavCorePlayerNode);
|
|
GD.Print("VavCorePlayer added to scene successfully");
|
|
|
|
UpdateStatus("VavCore Extension loaded successfully!");
|
|
GD.Print("=== VavCore Extension initialization complete ===");
|
|
|
|
// VavCore Extension 초기화 완료
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
GD.PrintErr($"=== VavCore Extension Error ===");
|
|
GD.PrintErr($"Exception: {ex.Message}");
|
|
GD.PrintErr($"Stack trace: {ex.StackTrace}");
|
|
UpdateStatus($"VavCore Extension error: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void UpdateStatus(string message)
|
|
{
|
|
_statusLabel.Text = message;
|
|
GD.Print($"Status: {message}");
|
|
}
|
|
|
|
// 버튼 이벤트 핸들러들
|
|
public void OnLoadButtonPressed()
|
|
{
|
|
GD.Print("=== Load button pressed ===");
|
|
UpdateStatus("Load button clicked - checking video file...");
|
|
|
|
// 파일 다이얼로그를 사용하여 비디오 파일 선택
|
|
// 또는 기본 테스트 파일 로드
|
|
string videoPath = "res://assets/videos/test_video.webm";
|
|
GD.Print($"Checking video path: {videoPath}");
|
|
|
|
// 실제 파일 경로로 변환해서 확인
|
|
string realPath = ProjectSettings.GlobalizePath(videoPath);
|
|
GD.Print($"Real file path: {realPath}");
|
|
|
|
if (FileAccess.FileExists(videoPath))
|
|
{
|
|
GD.Print("Video file exists - loading...");
|
|
LoadVideo(videoPath);
|
|
}
|
|
else
|
|
{
|
|
GD.PrintErr($"Test video file not found: {videoPath}");
|
|
GD.PrintErr($"Real path checked: {realPath}");
|
|
UpdateStatus("Test video file not found: " + videoPath);
|
|
|
|
// 디렉토리 내용 확인
|
|
var dir = DirAccess.Open("res://assets/videos/");
|
|
if (dir != null)
|
|
{
|
|
GD.Print("Files in assets/videos directory:");
|
|
dir.ListDirBegin();
|
|
var fileName = dir.GetNext();
|
|
while (fileName != "")
|
|
{
|
|
GD.Print($" - {fileName}");
|
|
fileName = dir.GetNext();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GD.PrintErr("Could not open assets/videos directory");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void LoadVideo(string videoPath)
|
|
{
|
|
GD.Print($"=== LoadVideo called with: {videoPath} ===");
|
|
|
|
if (_vavCorePlayerNode == null)
|
|
{
|
|
GD.PrintErr("VavCore Extension not available - _vavCorePlayerNode is null");
|
|
UpdateStatus("VavCore Extension not available");
|
|
return;
|
|
}
|
|
|
|
GD.Print("VavCorePlayer node is available, proceeding with video load...");
|
|
|
|
try
|
|
{
|
|
UpdateStatus($"Loading video: {videoPath}");
|
|
|
|
// 실제 VavCore Extension을 사용하여 비디오 로드
|
|
GD.Print("Calling _vavCorePlayerNode.LoadVideo()...");
|
|
bool success = _vavCorePlayerNode.LoadVideo(videoPath);
|
|
GD.Print($"LoadVideo returned: {success}");
|
|
|
|
if (success)
|
|
{
|
|
// 버튼 상태 업데이트
|
|
_playButton.Disabled = false;
|
|
_stopButton.Disabled = false;
|
|
|
|
UpdateStatus("Video loaded successfully!");
|
|
GD.Print("Video loading completed successfully!");
|
|
}
|
|
else
|
|
{
|
|
UpdateStatus("Failed to load video - VavCore returned false");
|
|
GD.PrintErr("Failed to load video - VavCore returned false");
|
|
}
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
GD.PrintErr($"Exception during video loading: {ex.Message}");
|
|
GD.PrintErr($"Stack trace: {ex.StackTrace}");
|
|
UpdateStatus($"Failed to load video: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
public void OnPlayButtonPressed()
|
|
{
|
|
GD.Print("Play button pressed");
|
|
|
|
if (_vavCorePlayerNode != null && _vavCorePlayerNode.IsVideoLoaded())
|
|
{
|
|
if (_vavCorePlayerNode.IsPlaying())
|
|
{
|
|
UpdateStatus("Already playing");
|
|
}
|
|
else
|
|
{
|
|
_vavCorePlayerNode.StartPlayback();
|
|
UpdateStatus("Playing video");
|
|
_playButton.Disabled = true;
|
|
_pauseButton.Disabled = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UpdateStatus("No video loaded - please load a video first");
|
|
}
|
|
}
|
|
|
|
public void OnPauseButtonPressed()
|
|
{
|
|
GD.Print("Pause button pressed");
|
|
|
|
if (_vavCorePlayerNode != null && _vavCorePlayerNode.IsVideoLoaded())
|
|
{
|
|
_vavCorePlayerNode.PausePlayback();
|
|
UpdateStatus("Paused");
|
|
_playButton.Disabled = false;
|
|
_pauseButton.Disabled = true;
|
|
}
|
|
else
|
|
{
|
|
UpdateStatus("No video to pause");
|
|
}
|
|
}
|
|
|
|
public void OnStopButtonPressed()
|
|
{
|
|
GD.Print("Stop button pressed");
|
|
|
|
if (_vavCorePlayerNode != null && _vavCorePlayerNode.IsVideoLoaded())
|
|
{
|
|
_vavCorePlayerNode.StopPlayback();
|
|
UpdateStatus("Stopped");
|
|
_playButton.Disabled = false;
|
|
_pauseButton.Disabled = true;
|
|
}
|
|
else
|
|
{
|
|
UpdateStatus("No video to stop");
|
|
}
|
|
}
|
|
|
|
} |