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:
        setMediaStatus(QMediaPlayer::LoadedMedia);
        if (mBuffering) {
            setMediaStatus(mBufferPercent == 100 ? QMediaPlayer::BufferedMedia
                                                 : QMediaPlayer::BufferingMedia);
        } else {
            onBufferChanged(100);
        }
        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:
        stop();
        setMediaStatus(QMediaPlayer::EndOfMedia);
        break;
    }
}
void QAndroidMediaPlayerControl::setMedia(const QMediaContent &mediaContent,
                                          QIODevice *stream)
{
    mMediaContent = mediaContent;
    mMediaStream = stream;

    const QString uri = mediaContent.canonicalUrl().toString();

    if (!uri.isEmpty())
        mMediaPlayer->setDataSource(uri);
    else
        setMediaStatus(QMediaPlayer::NoMedia);

    Q_EMIT mediaChanged(mMediaContent);

    resetBufferingProgress();

    // reset some properties
    setAudioAvailable(false);
    setVideoAvailable(false);
    setSeekable(true);
}
void QAndroidMediaPlayerControl::setMedia(const QMediaContent &mediaContent,
                                          QIODevice *stream)
{
    mMediaContent = mediaContent;
    mMediaStream = stream;

    if (mVideoOutput && !mMediaPlayer->display()) {
        // if a video output is set but the video texture is not ready, delay loading the media
        // since it can cause problems on some hardware
        mPendingSetMedia = true;
        return;
    }

    const QUrl url = mediaContent.canonicalUrl();
    QString mediaPath;
    if (url.scheme() == QLatin1String("qrc")) {
        const QString path = url.toString().mid(3);
        mTempFile.reset(QTemporaryFile::createNativeFile(path));
        if (!mTempFile.isNull())
            mediaPath = QLatin1String("file://") + mTempFile->fileName();
    } else {
        mediaPath = url.toString();
    }

    if (!mediaPath.isEmpty())
        mMediaPlayer->setDataSource(mediaPath);
    else
        setMediaStatus(QMediaPlayer::NoMedia);

    Q_EMIT mediaChanged(mMediaContent);

    resetBufferingProgress();

    // reset some properties
    setAudioAvailable(false);
    setVideoAvailable(false);
    setSeekable(true);
}