Skip to content

Commit

Permalink
AVFMediaPlayer: Try to play asset even if 'playable' property is false
Browse files Browse the repository at this point in the history
Sometimes an AVAsset can report to be not playable even if the asset
can still be played. That is why we shouldn't stop trying to play based
on this check only. To determine if an asset is truly playable or not,
we should only need to rely on the 'status' property of the AVPlayerItem
using the asset, as that one will never be AVPlayerStatusReadyToPlay
if the asset is not playable and will instead fail throwing the
appropriate errors.

Fixes: QTBUG-98102
Pick-to: 6.2 6.5
Change-Id: I26d319fe120335cdfbc09cd6aa68ce7e8f282699
Reviewed-by: Lars Knoll <[email protected]>
Reviewed-by: Artem Dyomin <[email protected]>
  • Loading branch information
dorisverria1 committed Mar 23, 2023
1 parent 87c7e03 commit c21b3ad
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/plugins/multimedia/darwin/mediaplayer/avfmediaplayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -182,32 +182,33 @@ - (void) prepareToPlayAsset:(AVURLAsset *)asset
qDebug() << Q_FUNC_INFO << "isPlayable: " << [asset isPlayable];
#endif
if (!asset.playable)
qWarning() << "Asset reported to be not playable. Playback of this asset may not be possible.";

//At this point we're ready to set up for playback of the asset.
//Stop observing our prior AVPlayerItem, if we have one.
if (m_playerItem)
{
//Remove existing player item key value observers and notifications.
[self unloadMedia];
}

//Create a new instance of AVPlayerItem from the now successfully loaded AVAsset.
m_playerItem = [AVPlayerItem playerItemWithAsset:asset];
if (!m_playerItem) {
qWarning() << "Failed to create player item";
//Generate an error describing the failure.
NSString *localizedDescription = NSLocalizedString(@"Item cannot be played", @"Item cannot be played description");
NSString *localizedFailureReason = NSLocalizedString(@"The assets tracks were loaded, but could not be made playable.", @"Item cannot be played failure reason");
NSString *localizedFailureReason = NSLocalizedString(@"The assets tracks were loaded, but couldn't create player item.", @"Item cannot be played failure reason");
NSDictionary *errorDict = [NSDictionary dictionaryWithObjectsAndKeys:
localizedDescription, NSLocalizedDescriptionKey,
localizedFailureReason, NSLocalizedFailureReasonErrorKey,
nil];
NSError *assetCannotBePlayedError = [NSError errorWithDomain:@"StitchedStreamPlayer" code:0 userInfo:errorDict];

[self assetFailedToPrepareForPlayback:assetCannotBePlayedError];

return;
}

//At this point we're ready to set up for playback of the asset.
//Stop observing our prior AVPlayerItem, if we have one.
if (m_playerItem)
{
//Remove existing player item key value observers and notifications.
[self unloadMedia];
}

//Create a new instance of AVPlayerItem from the now successfully loaded AVAsset.
m_playerItem = [AVPlayerItem playerItemWithAsset:asset];

//Observe the player item "status" key to determine when it is ready to play.
[m_playerItem addObserver:self
forKeyPath:AVF_STATUS_KEY
Expand Down

0 comments on commit c21b3ad

Please sign in to comment.