@echo off
chcp 65001 >nul
setlocal
cd /d "%~dp0"

rem 查找 conda：优先使用 PATH 中的 conda，否则在常见安装目录中查找
set "CONDA_BASE="
where conda >nul 2>nul
if not errorlevel 1 (
    for /f "delims=" %%i in ('conda info --base') do set "CONDA_BASE=%%i"
)
if not defined CONDA_BASE (
    for %%C in ("%USERPROFILE%\anaconda3" "%USERPROFILE%\miniconda3" "%ProgramData%\Anaconda3" "%ProgramData%\Miniconda3" "C:\anaconda3" "C:\miniconda3") do (
        if exist "%%~C\Scripts\activate.bat" set "CONDA_BASE=%%~C"
    )
)
if not defined CONDA_BASE (
    echo [错误] 未找到 conda，请先安装 Anaconda 或 Miniconda。
    pause
    exit /b 1
)

call "%CONDA_BASE%\Scripts\activate.bat" mediaplayer
if errorlevel 1 (
    echo [错误] 激活 mediaplayer 环境失败，请确认已创建该环境。
    pause
    exit /b 1
)

python -c "import sys; sys.exit(0 if 'mediaplayer' in sys.prefix else 1)" >nul 2>nul
if errorlevel 1 (
    echo [错误] mediaplayer 环境未正确激活。
    pause
    exit /b 1
)

python media_player.py %*
if errorlevel 1 pause
