279 lines
9.3 KiB
C++
279 lines
9.3 KiB
C++
#include "pch.h"
|
|
#include "MultiVideoPage.xaml.h"
|
|
#if __has_include("MultiVideoPage.g.cpp")
|
|
#include "MultiVideoPage.g.cpp"
|
|
#endif
|
|
|
|
using namespace winrt;
|
|
using namespace winrt::Microsoft::UI::Xaml;
|
|
using namespace winrt::Microsoft::UI::Xaml::Controls;
|
|
|
|
namespace winrt::Vav2Player::implementation
|
|
{
|
|
MultiVideoPage::MultiVideoPage()
|
|
{
|
|
InitializeComponent();
|
|
UpdateStatus(L"Multi Video - Ready");
|
|
|
|
// Create initial video grid (Single video layout)
|
|
CreateVideoGrid(LayoutType::Single);
|
|
}
|
|
|
|
winrt::Windows::Foundation::IAsyncAction MultiVideoPage::LoadVideoButton_Click(winrt::Windows::Foundation::IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&)
|
|
{
|
|
try
|
|
{
|
|
// Create file picker
|
|
winrt::Windows::Storage::Pickers::FileOpenPicker picker;
|
|
picker.ViewMode(winrt::Windows::Storage::Pickers::PickerViewMode::Thumbnail);
|
|
picker.SuggestedStartLocation(winrt::Windows::Storage::Pickers::PickerLocationId::VideosLibrary);
|
|
|
|
// Add supported video file types
|
|
picker.FileTypeFilter().Append(L".webm");
|
|
picker.FileTypeFilter().Append(L".mkv");
|
|
picker.FileTypeFilter().Append(L".mp4");
|
|
picker.FileTypeFilter().Append(L".avi");
|
|
|
|
// Initialize picker with window handle - use simple approach for Page
|
|
try {
|
|
auto initializeWithWindow = picker.as<IInitializeWithWindow>();
|
|
|
|
// Get the active window handle
|
|
HWND hWnd = GetActiveWindow();
|
|
if (hWnd == nullptr)
|
|
{
|
|
hWnd = GetForegroundWindow();
|
|
}
|
|
|
|
if (hWnd != nullptr)
|
|
{
|
|
initializeWithWindow->Initialize(hWnd);
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
// If window handle initialization fails, continue without it
|
|
// FileOpenPicker might still work in some cases
|
|
}
|
|
|
|
// Show picker and get selected file
|
|
auto file = co_await picker.PickSingleFileAsync();
|
|
if (file != nullptr)
|
|
{
|
|
auto filePath = file.Path();
|
|
m_currentVideoPath = filePath;
|
|
|
|
// Load video to all players
|
|
UpdateStatus(L"Loading video to all players...");
|
|
for (auto& player : m_videoPlayers)
|
|
{
|
|
player.LoadVideo(filePath);
|
|
}
|
|
UpdateStatus(winrt::hstring(L"Video loaded to " + std::to_wstring(m_videoPlayers.size()) + L" players: " + filePath.c_str()));
|
|
}
|
|
else
|
|
{
|
|
UpdateStatus(L"No file selected");
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
UpdateStatus(L"Error opening file picker");
|
|
}
|
|
}
|
|
|
|
void MultiVideoPage::PlayAllButton_Click(winrt::Windows::Foundation::IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&)
|
|
{
|
|
for (auto& player : m_videoPlayers)
|
|
{
|
|
if (player.IsVideoLoaded())
|
|
{
|
|
player.Play();
|
|
}
|
|
}
|
|
UpdateStatus(L"Playing all videos");
|
|
}
|
|
|
|
void MultiVideoPage::PauseAllButton_Click(winrt::Windows::Foundation::IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&)
|
|
{
|
|
for (auto& player : m_videoPlayers)
|
|
{
|
|
if (player.IsVideoPlaying())
|
|
{
|
|
player.Pause();
|
|
}
|
|
}
|
|
UpdateStatus(L"Paused all videos");
|
|
}
|
|
|
|
void MultiVideoPage::StopAllButton_Click(winrt::Windows::Foundation::IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&)
|
|
{
|
|
for (auto& player : m_videoPlayers)
|
|
{
|
|
if (player.IsVideoLoaded())
|
|
{
|
|
player.Stop();
|
|
}
|
|
}
|
|
UpdateStatus(L"Stopped all videos");
|
|
}
|
|
|
|
void MultiVideoPage::LayoutComboBox_SelectionChanged(winrt::Windows::Foundation::IInspectable const&, winrt::Microsoft::UI::Xaml::Controls::SelectionChangedEventArgs const& e)
|
|
{
|
|
// Skip if UI not ready yet
|
|
try {
|
|
if (!VideoGrid() || e.AddedItems().Size() == 0) {
|
|
return;
|
|
}
|
|
|
|
if (auto comboBox = e.AddedItems().GetAt(0).try_as<ComboBoxItem>())
|
|
{
|
|
auto content = comboBox.Content().as<hstring>();
|
|
if (content == L"Single Video")
|
|
{
|
|
CreateVideoGrid(LayoutType::Single);
|
|
}
|
|
else if (content == L"2x2 Grid")
|
|
{
|
|
CreateVideoGrid(LayoutType::Grid2x2);
|
|
}
|
|
else if (content == L"1x4 Strip")
|
|
{
|
|
CreateVideoGrid(LayoutType::Strip1x4);
|
|
}
|
|
else if (content == L"3x3 Grid")
|
|
{
|
|
CreateVideoGrid(LayoutType::Grid3x3);
|
|
}
|
|
}
|
|
}
|
|
catch (...) {
|
|
// Ignore errors during initialization
|
|
}
|
|
}
|
|
|
|
void MultiVideoPage::UseHardwareRenderingCheckBox_Checked(winrt::Windows::Foundation::IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&)
|
|
{
|
|
UpdateStatus(L"Hardware rendering enabled");
|
|
}
|
|
|
|
void MultiVideoPage::UseHardwareRenderingCheckBox_Unchecked(winrt::Windows::Foundation::IInspectable const&, winrt::Microsoft::UI::Xaml::RoutedEventArgs const&)
|
|
{
|
|
UpdateStatus(L"Hardware rendering disabled");
|
|
}
|
|
|
|
// Helper methods - simplified implementations
|
|
void MultiVideoPage::CreateVideoGrid(LayoutType layout)
|
|
{
|
|
try {
|
|
if (!VideoGrid()) {
|
|
return;
|
|
}
|
|
|
|
ClearVideoGrid();
|
|
m_currentLayout = layout;
|
|
|
|
int rows = 1, cols = 1;
|
|
switch (layout)
|
|
{
|
|
case LayoutType::Single: rows = 1; cols = 1; break;
|
|
case LayoutType::Grid2x2: rows = 2; cols = 2; break;
|
|
case LayoutType::Strip1x4: rows = 1; cols = 4; break;
|
|
case LayoutType::Grid3x3: rows = 3; cols = 3; break;
|
|
}
|
|
|
|
VideoGrid().RowDefinitions().Clear();
|
|
VideoGrid().ColumnDefinitions().Clear();
|
|
m_videoPlayers.clear();
|
|
|
|
for (int r = 0; r < rows; ++r)
|
|
{
|
|
auto rowDef = RowDefinition();
|
|
rowDef.Height(GridLengthHelper::FromValueAndType(1, GridUnitType::Star));
|
|
VideoGrid().RowDefinitions().Append(rowDef);
|
|
}
|
|
|
|
for (int c = 0; c < cols; ++c)
|
|
{
|
|
auto colDef = ColumnDefinition();
|
|
colDef.Width(GridLengthHelper::FromValueAndType(1, GridUnitType::Star));
|
|
VideoGrid().ColumnDefinitions().Append(colDef);
|
|
}
|
|
|
|
// Create VideoPlayerControl instances and add them to the grid
|
|
for (int r = 0; r < rows; ++r)
|
|
{
|
|
for (int c = 0; c < cols; ++c)
|
|
{
|
|
auto videoPlayer = winrt::make<winrt::Vav2Player::implementation::VideoPlayerControl2>();
|
|
|
|
// Set grid position
|
|
videoPlayer.SetValue(Grid::RowProperty(), winrt::box_value(r));
|
|
videoPlayer.SetValue(Grid::ColumnProperty(), winrt::box_value(c));
|
|
|
|
// Add margin for visual separation
|
|
videoPlayer.Margin({2, 2, 2, 2});
|
|
|
|
// Add to grid
|
|
VideoGrid().Children().Append(videoPlayer);
|
|
|
|
// Store reference
|
|
m_videoPlayers.push_back(videoPlayer);
|
|
}
|
|
}
|
|
|
|
// Load current video to all players if available
|
|
if (!m_currentVideoPath.empty())
|
|
{
|
|
for (auto& player : m_videoPlayers)
|
|
{
|
|
player.LoadVideo(m_currentVideoPath);
|
|
}
|
|
}
|
|
|
|
UpdateStatus(winrt::hstring(L"Created " + std::to_wstring(rows) + L"x" + std::to_wstring(cols) + L" video grid (" + std::to_wstring(m_videoPlayers.size()) + L" players)"));
|
|
}
|
|
catch (...) {
|
|
UpdateStatus(L"Error creating video grid");
|
|
}
|
|
}
|
|
|
|
void MultiVideoPage::ClearVideoGrid()
|
|
{
|
|
try {
|
|
if (VideoGrid()) {
|
|
VideoGrid().Children().Clear();
|
|
}
|
|
m_videoPlayers.clear();
|
|
}
|
|
catch (...) {
|
|
// Ignore errors during clearing
|
|
}
|
|
}
|
|
|
|
winrt::Windows::Foundation::IAsyncAction MultiVideoPage::LoadVideoToAllPlayers(winrt::hstring const& videoPath)
|
|
{
|
|
co_await resume_background();
|
|
// Implementation would load video to all players
|
|
co_return;
|
|
}
|
|
|
|
winrt::Windows::Foundation::IAsyncAction MultiVideoPage::PickVideoFile()
|
|
{
|
|
co_await resume_background();
|
|
// Implementation would show file picker
|
|
co_return;
|
|
}
|
|
|
|
void MultiVideoPage::UpdateStatus(winrt::hstring const& message)
|
|
{
|
|
try {
|
|
if (StatusDisplay()) {
|
|
StatusDisplay().Text(message);
|
|
}
|
|
} catch (...) {
|
|
// Ignore if UI not ready yet
|
|
}
|
|
OutputDebugStringA((winrt::to_string(message) + "\n").c_str());
|
|
}
|
|
} |