/*
 * Copyright (C) 2022, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * Authors: Xin Li <lixin@kylinos.cn>
 */
#include "playcontrol.h"

PlayControl::PlayControl(QObject *parent) : QObject(parent)
{
    player = new QMediaPlayer(this);
    moveTimer = new QTimer(this); // QTimer
    clipMoveTimer = new QTimer(this);
    qDebug() << "执行1次";
}

QMediaPlayer::State PlayControl::getAudioState()
{
    m_state = player->state();
    return m_state;
}

void PlayControl::play_Audio(QString filePath)
{

    if (isPlayingPath != filePath) {

        isPlayingPath = filePath; //非原路径的播放
        player->setMedia(QUrl::fromLocalFile(filePath));
        player->setVolume(85);
        player->play();
        qDebug() << "非原路径播放:" << filePath;

    } else {
        player->play();
        qDebug() << "原路径播放:" << filePath;
    }
}

void PlayControl::pause_Audio()
{
    qDebug() << "暂停了" ;
    player->pause();
}

void PlayControl::stop()
{
    player->stop();
}

void PlayControl::setPosition(qint64 position)
{
    if (qAbs(player->position() - position) > 99)
        player->setPosition(position);
    qDebug() << "数值:" << position;
}

PlayControl::~PlayControl() {}
