Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions iOS/BDAlphaPlayer/Classes/BDAlphaPlayerMetalView.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ @interface BDAlphaPlayerMetalView ()

@property (atomic, assign) BOOL hasDestroyed;

@property (nonatomic, strong) AVPlayer *audioPlayer;

@end

@implementation BDAlphaPlayerMetalView
Expand Down Expand Up @@ -141,6 +143,16 @@ - (void)play
[self renderOutput:output resourceModel:self.model completion:^{
[weakSelf renderCompletion];
}];

// 播放音频
if (output.audioItem) {
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
[session setActive:YES error:nil];

self.audioPlayer = [[AVPlayer alloc] initWithPlayerItem:output.audioItem];
[self.audioPlayer play];
}
}

- (void)renderCompletion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ typedef NS_ENUM(NSUInteger, BDAlphaPlayerAssetReaderOutputErrorCode) {

@property (nonatomic, assign, readonly) CGSize videoSize;

@property (nonatomic, strong, readonly) AVPlayerItem *audioItem;

- (BOOL)hasNextSampleBuffer;

- (CMSampleBufferRef const _Nullable)copyNextSampleBuffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ - (void)setupWithURL:(NSURL *)url error:(NSError * _Nullable __autoreleasing * _
return;
}

// 提取音轨
NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
AVAssetTrack *audioTrack = [audioTracks firstObject];
if (audioTrack) {
// 存在音轨,转成AVPlayerItem
_audioItem = [AVPlayerItem playerItemWithAsset:audioTrack.asset];
}

NSArray *videoTracks = [asset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *videoTrack = [videoTracks firstObject];
if (!videoTrack) {
Expand Down
19 changes: 0 additions & 19 deletions iOS/Example/BDAlphaPlayerDemo/BDAlphaPlayerDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,6 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
6 changes: 3 additions & 3 deletions iOS/Example/BDAlphaPlayerDemo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- BDAlphaPlayer (1.1.0)
- BDAlphaPlayer (1.2.0)

DEPENDENCIES:
- BDAlphaPlayer (from `../../../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../../../"

SPEC CHECKSUMS:
BDAlphaPlayer: 6ec0535dbbac6b089e94acb5559dcdf77dd1d5a8
BDAlphaPlayer: 8af2048ee8ef8c31a73a99f83882cf4242e89df0

PODFILE CHECKSUM: a2a7c83a00e25dc193359c91e412457a63e7fbad

COCOAPODS: 1.8.4
COCOAPODS: 1.10.1