Skip to content

Commit

Permalink
Fix #2371 Video freezes on the first frame when played on Apple TV
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Feb 5, 2025
1 parent 001089f commit 52ff468
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ list(APPEND _AX_SRC ${_AX_HEADER})

add_library(${_AX_CORE_LIB} ${_AX_SRC})

if(APPLE)
set_xcode_property(${_AX_CORE_LIB} CLANG_ENABLE_OBJC_WEAK "YES")
endif()

if(WASM)
if(${EMSCRIPTEN_VERSION} VERSION_GREATER_EQUAL "3.1.51")
target_link_options(${_AX_CORE_LIB} PUBLIC -sGL_ENABLE_GET_PROC_ADDRESS)
Expand Down
17 changes: 14 additions & 3 deletions core/media/AvfMediaEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ of this software and associated documentation files (the "Software"), to deal
# include <assert.h>
# include "yasio/string_view.hpp"
# include "yasio/endian_portable.hpp"
# include "yasio/sz.hpp"

#if TARGET_OS_IPHONE
# import <UIKit/UIKit.h>
Expand Down Expand Up @@ -361,8 +360,20 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
}
}

if (_bAutoPlay)
this->play();
if (_bAutoPlay) {
// fix issue: #2371
// tvOS: we need delay on frame to invoke play even through invoking from KOV playerItem.status==AVPlayerItemStatusReadyToPlay
// otherwise, the player.timeControlStatus will be AVPlayerTimeControlStatusPaused until invoke [player play] at next frame
__weak AVPlayer* player = _player;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (player != nil)
[player play];
});

_playbackEnded = false;
_state = MEMediaState::Playing;
fireMediaEvent(MEMediaEventType::Playing);
}
}

bool AvfMediaEngine::transferVideoFrame()
Expand Down

0 comments on commit 52ff468

Please sign in to comment.