gpt4 book ai didi

ios - IOS的AudioToolBox出现EXC_BAD_ACCESS如何解决

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:51:55 25 4
gpt4 key购买 nike

我需要帮助解决在 MPMoviePlayerController 和 MPMusicPlayerController 之间转换期间 AudioToolBox (AVAudioSessionPropertyListener) 中偶尔发生 EXC_BAD_ACCESS 崩溃的问题。以下是调用轨迹:

OS Version:      iPhone OS 5.1 (9B176)
Report Version: 104

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000009
Crashed Thread: 0

Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3676ef78 objc_msgSend + 16
1 AVFoundation 0x31e60b1c _ZL30AVAudioSessionPropertyListenerPvmmPKv + 236
2 AudioToolbox 0x3630b300 AudioSessionPropertyListeners::CallPropertyListenersImp(unsigned long, unsigned long, void const*) + 268
3 AudioToolbox 0x3630b5de AudioSessionPropertyListeners::CallPropertyListeners(unsigned long, unsigned long, void const*) + 234
4 AudioToolbox 0x3630925a SSServer_AudioSessionInterruptionListenerMessage + 50
5 AudioToolbox 0x362b0d2c _XAudioSessionInterruptionListenerMessage + 56
6 AudioToolbox 0x36245cdc mshMIGPerform + 368
7 CoreFoundation 0x3532151c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
8 CoreFoundation 0x353214be __CFRunLoopDoSource1 + 134
9 CoreFoundation 0x3532030c __CFRunLoopRun + 1364
10 CoreFoundation 0x352a349e CFRunLoopRunSpecific + 294
11 CoreFoundation 0x352a3366 CFRunLoopRunInMode + 98
12 GraphicsServices 0x3659f432 GSEventRunModal + 130
13 UIKit 0x32399e76 UIApplicationMain + 1074
14 MyGreatApp 0x00054986 main (main.m:14)
15 MyGreatApp 0x00054944 start + 32

我的应用交替使用音乐播放器和电影播放器​​。电影播放器​​用于播放播客。每次播放新播客时,电影播放器​​都会分配一个自动释放。当我用完电影播放器​​后,我会删除我设置的所有观察者,确保电影播放器​​已停止,然后重新启动音乐播放器。

下面是一些初始化电影播放器​​使用的相关代码:

[musicPlayer pause];

self.moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL: address] autorelease]; // Release the old moviePlayer and create a new one.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePreloadDidFinish:) name:MPMoviePlayerLoadStateDidChangeNotification object:self.moviePlayer];

// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];

// Register to receive a notification when the movie playback state changes (specifically looking for the state of interrupted).
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackStateChanged:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.moviePlayer];

[self.moviePlayer play];

电影可以在播放完后结束,或者用户可以通过按快进按钮终止电影。下面是处理这两种情况的相关代码:

-(IBAction) fastForwardMovie: (id) sender {

// The self.moviePlayer is still playing, but the user wants to skip the rest of the movie/podcast.
// Lets fake a movie playback did finish event
NSNotification *notification = [NSNotification notificationWithName:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self moviePlayBackDidFinish: notification]; // Fake a finished playback so that the music player can be restarted
return;
}


// Notification called when the movie FINISHED playing.
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
// Remove further notifications until the next time we need the movie player
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:self.moviePlayer] ;
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer] ;
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.moviePlayer] ;


// Get rid of the movie player
self.moviePlayer.initialPlaybackTime = -1; // seems that the best way to kill the movie player is first setting the playback time to -1
[self.moviePlayer stop]; // followed by stopping the player

[musicPlayer play];
}

电影(播客)结束后,即使发生崩溃(但应用程序已终止),音乐也会播放。这是因为我使用的是 iPod 音乐播放器,但这可能表明问题与电影播放器​​有关。

最后一点。我已尝试仔细遵循 Apple 的 Audio Session Programming Guide 指南,其中指出当所需配置是混合所有音频时,您应该“使用可混合类别配置配置 Audio Session ”和“利用电影播放器的默认 useApplicationAudioSession 值为 YES。

谁能帮我弄清楚我可能做错了什么导致 AVAudioSessionPropertyListener 因 EXC_BAD_ACCESS 而崩溃?或者至少你能给我一个建议,告诉我如何隔离这个问题以确定根本原因吗?

最佳答案

尝试调用 [musicPlayer performSelectorOnMainThread:@selector(play) ...] 吗?

关于ios - IOS的AudioToolBox出现EXC_BAD_ACCESS如何解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10271066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com