import QtQuick
import QtMultimedia
import QtQuick.Window

/**
 * 适配 Plasma 6 的极简视频欢迎屏幕 (Splash Screen)
 * 针对硬件解码兼容性进行了优化
 * 请将此文件放置在：~/.local/share/plasma/look-and-feel/com.user.videosplash/contents/splash/Splash.qml
 */

Item {
    id: root
    width: Screen.width
    height: Screen.height

    property int stage

    Rectangle {
        id: background
        anchors.fill: parent
        color: "black"

        // 使用 MediaPlayer + VideoOutput 替代 Video 控件，以获得更好的兼容性和错误处理
        MediaPlayer {
            id: player
            source: "background.mp4"
            videoOutput: videoOutput
            loops: MediaPlayer.Infinite

            // 欢迎屏幕强制静音，减少音频后端初始化失败的风险
            audioOutput: null

            onErrorOccurred: (error, errorString) => {
                console.log("Splash Video Error: " + errorString);
            }

            Component.onCompleted: {
                player.play();
            }
        }

        VideoOutput {
            id: videoOutput
            anchors.fill: parent
            // 填充模式：保持比例裁剪
            fillMode: VideoOutput.PreserveAspectCrop
        }
    }

    // 界面淡入
    opacity: 0
    Component.onCompleted: {
        fadeInAnimation.start();
    }

    PropertyAnimation {
        id: fadeInAnimation
        target: root
        property: "opacity"
        from: 0
        to: 1
        duration: 1000
        easing.type: Easing.InOutQuad
    }
}
