summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-11-02 10:49:29 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-11-02 15:21:24 +0000
commit86ded826ab68c6d72aeef2993ac04aba264cde83 (patch)
tree18f2d7988dfa2c8d802922b2874bf0850f5dad5d
parent99a52e6f8f847cbb59d9decbdd82b0712a4e9035 (diff)
downloadqtmultimedia-86ded826ab68c6d72aeef2993ac04aba264cde83.tar.gz
Force subtitles to get laoded when selecting a subtitle track
AVFoundation by default tries to apply user specific selection citeria when selecting audio and subtitle tracks. Unfortunately, this meant subtitles would not get rendered at all if they were initially disabled. This change ensures we enable them in the player when the user selects a subtitle track. In addition, we make sure they are disabled by default when you first load the media file. Fixes: QTBUG-96447 Change-Id: Ibfeb96ef54728324395f7d4bac4d035b8ee1d212 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Doris Verria <doris.verria@qt.io> (cherry picked from commit 82c70bce11abea285a5e06a357da4c9434db0529) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/multimedia/platform/darwin/mediaplayer/avfmediaplayer.mm27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayer.mm b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayer.mm
index 6b0514e6e..1a73618b6 100644
--- a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayer.mm
+++ b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayer.mm
@@ -592,6 +592,11 @@ void AVFMediaPlayer::setMedia(const QUrl &content, QIODevice *stream)
m_metaData.clear();
metaDataChanged();
}
+ for (int i = 0; i < QPlatformMediaPlayer::NTrackTypes; ++i) {
+ tracks[i].clear();
+ nativeTracks[i].clear();
+ }
+ tracksChanged();
const QMediaPlayer::MediaStatus oldMediaStatus = m_mediaStatus;
const QMediaPlayer::PlaybackState oldState = m_state;
@@ -1089,7 +1094,10 @@ void AVFMediaPlayer::streamDestroyed()
void AVFMediaPlayer::updateTracks()
{
+ bool firstLoad = true;
for (int i = 0; i < QPlatformMediaPlayer::NTrackTypes; ++i) {
+ if (tracks[i].count())
+ firstLoad = false;
tracks[i].clear();
nativeTracks[i].clear();
}
@@ -1120,6 +1128,9 @@ void AVFMediaPlayer::updateTracks()
}
}
}
+ // subtitles are disabled by default
+ if (firstLoad)
+ setActiveTrack(SubtitleStream, -1);
}
Q_EMIT tracksChanged();
}
@@ -1127,6 +1138,22 @@ void AVFMediaPlayer::updateTracks()
void AVFMediaPlayer::setActiveTrack(QPlatformMediaPlayer::TrackType type, int index)
{
const auto &t = nativeTracks[type];
+ if (type == QPlatformMediaPlayer::SubtitleStream) {
+ // subtitle streams are not always automatically enabled on macOS/iOS.
+ // this hack ensures they get enables and we actually get the text
+ AVPlayerItem *playerItem = m_observer.m_playerItem;
+ if (playerItem) {
+ AVAsset *asset = playerItem.asset;
+ if (!asset)
+ return;
+ AVMediaSelectionGroup *group = [asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
+ if (!group)
+ return;
+ auto *options = group.options;
+ if (options.count)
+ [playerItem selectMediaOption:options.firstObject inMediaSelectionGroup:group];
+ }
+ }
for (int i = 0; i < t.count(); ++i)
t.at(i).enabled = (i == index);
}