Пример #1
0
void QAndroidMediaPlayerControl::onBufferChanged(qint32 percent)
{
    mBuffering = percent != 100;
    mBufferPercent = percent;
    Q_EMIT bufferStatusChanged(mBufferPercent);

    updateAvailablePlaybackRanges();

    if (mBufferPercent == 100)
        setMediaStatus(QMediaPlayer::BufferedMedia);
}
void QAndroidMediaPlayerControl::onMediaPlayerInfo(qint32 what, qint32 extra)
{
    switch (what) {
    case JMediaPlayer::MEDIA_PLAYER_INVALID_STATE:
        setError(what, QStringLiteral("Error: Invalid state"));
        break;
    case JMediaPlayer::MEDIA_PLAYER_PREPARING:
        setMediaStatus(QMediaPlayer::LoadingMedia);
        setState(QMediaPlayer::StoppedState);
        break;
    case JMediaPlayer::MEDIA_PLAYER_READY:
        if (mBuffering) {
            setMediaStatus(mBufferPercent == 100 ? QMediaPlayer::BufferedMedia
                                                 : QMediaPlayer::BufferingMedia);
        } else {
            setMediaStatus(QMediaPlayer::LoadedMedia);
            mBufferPercent = 100;
            Q_EMIT bufferStatusChanged(mBufferPercent);
            updateAvailablePlaybackRanges();
        }
        setAudioAvailable(true);
        mMediaPlayerReady = true;
        flushPendingStates();
        break;
    case JMediaPlayer::MEDIA_PLAYER_DURATION:
        Q_EMIT durationChanged(extra);
        break;
    case JMediaPlayer::MEDIA_PLAYER_PROGRESS:
        Q_EMIT positionChanged(extra);
        break;
    case JMediaPlayer::MEDIA_PLAYER_FINISHED:
        setState(QMediaPlayer::StoppedState);
        setMediaStatus(QMediaPlayer::EndOfMedia);
        break;
    }
}