- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我不知道问题的原因是什么,当播放器尝试播放测试音频文件时它崩溃了,但只在模拟器中。在真实设备上它运行良好。如果你想看一下,我已经粘贴了下面的代码,包括它给我的一些调试信息......如果我找不到这个崩溃的根源,只要它运行良好,它会通过 Apple 的 QA 程序吗在设备本身上?
这个 isa -> unknown class 可能是问题所在吗?
在此方法中,它在 [p play]
上崩溃:
-(void)startPlaybackForPlayer:(AVAudioPlayer*)p
{
if ([p play])
{
[self updateViewForPlayerState:p];
}
else
NSLog(@"Could not play %@\n", p.url);
}
-
#import "AudioPlayerViewController.h"
@interface AudioPlayerViewController ()
{
//AVAudioPlayer *player;
}
@property (nonatomic,strong) AVAudioPlayer *player;
@end
@implementation AudioPlayerViewController
-(void)updateCurrentTimeForPlayer:(AVAudioPlayer *)p
{
self.currentTime.text = [NSString stringWithFormat:@"%d:%02d", (int)p.currentTime / 60, (int)p.currentTime % 60, nil];
self.progressBar.value = p.currentTime;
}
- (void)updateCurrentTime
{
[self updateCurrentTimeForPlayer:self.player];
}
- (void)updateViewForPlayerState:(AVAudioPlayer *)p
{
[self updateCurrentTimeForPlayer:p];
if (self.updateTimer)
[self.updateTimer invalidate];
if (p.playing)
{
[self.playButton setImage:((p.playing == YES) ? pauseBtnBG : playBtnBG) forState:UIControlStateNormal];
//[lvlMeter_in setPlayer:p];
self.updateTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(updateCurrentTime) userInfo:p repeats:YES];
}
else
{
[self.playButton setImage:((p.playing == YES) ? pauseBtnBG : playBtnBG) forState:UIControlStateNormal];
//[lvlMeter_in setPlayer:nil];
self.updateTimer = nil;
}
}
- (void)updateViewForPlayerStateInBackground:(AVAudioPlayer *)p
{
[self updateCurrentTimeForPlayer:p];
if (p.playing)
{
[self.playButton setImage:((p.playing == YES) ? pauseBtnBG : playBtnBG) forState:UIControlStateNormal];
}
else
{
[self.playButton setImage:((p.playing == YES) ? pauseBtnBG : playBtnBG) forState:UIControlStateNormal];
}
}
-(void)updateViewForPlayerInfo:(AVAudioPlayer*)p
{
self.duration.text = [NSString stringWithFormat:@"%d:%02d", (int)p.duration / 60, (int)p.duration % 60, nil];
self.progressBar.maximumValue = p.duration;
self.volumeSlider.value = p.volume;
}
- (void)rewind
{
//AVAudioPlayer *p = rewTimer.userInfo;
//p.currentTime-= SKIP_TIME;
//[self updateCurrentTimeForPlayer:p];
}
- (void)ffwd
{
//AVAudioPlayer *p = ffwTimer.userInfo;
//p.currentTime+= SKIP_TIME;
//[self updateCurrentTimeForPlayer:p];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"### AudioPlayerViewController Initiallized");
playBtnBG = [UIImage imageNamed:@"play.png"]; // Retain, maybe make strong
pauseBtnBG = [UIImage imageNamed:@"pause.png"];
[self.playButton setImage:playBtnBG forState:UIControlStateNormal];
[self registerForBackgroundNotifications];
self.updateTimer = nil;
//rewTimer = nil;
//ffwTimer = nil;
self.duration.adjustsFontSizeToFitWidth = YES;
self.currentTime.adjustsFontSizeToFitWidth = YES;
self.progressBar.minimumValue = 0.0;
// Load the the sample file, use mono or stero sample
#warning samplefile does not exist
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"bubbles" ofType:@"m4a"]];
//NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"sample2ch" ofType:@"m4a"]];
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
if (self.player)
{
self.fileName.text = [NSString stringWithFormat: @"%@ (%d ch.)", [[self.player.url relativePath] lastPathComponent], self.player.numberOfChannels, nil];
[self updateViewForPlayerInfo:self.player];
[self updateViewForPlayerState:self.player];
self.player.numberOfLoops = 1;
self.player.delegate = self;
}
OSStatus result = AudioSessionInitialize(NULL, NULL, NULL, NULL);
if (result)
NSLog(@"Error initializing audio session! %ld", result);
[[AVAudioSession sharedInstance] setDelegate: self];
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];
if (setCategoryError)
NSLog(@"Error setting category! %@", setCategoryError);
#warning did change here - migth cause bug
//result = AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, RouteChangeListener, (__bridge void *)(self));
if (result)
NSLog(@"Could not add property listener! %ld", result);
/*
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
self.player.delegate = self;
[self.player prepareToPlay];
[self playAudio];
*/
}
-(void)pausePlaybackForPlayer:(AVAudioPlayer*)p
{
[p pause];
[self updateViewForPlayerState:p];
}
-(void)startPlaybackForPlayer:(AVAudioPlayer*)p
{
if ([p play])
{
[self updateViewForPlayerState:p];
}
else
NSLog(@"Could not play %@\n", p.url);
}
- (IBAction)playButtonPressed:(UIButton *)sender
{
if (self.player.playing == YES)
[self pausePlaybackForPlayer: self.player];
else
[self startPlaybackForPlayer: self.player];
}
- (IBAction)rewButtonPressed:(UIButton *)sender
{
/*
if (rewTimer) [rewTimer invalidate];
rewTimer = [NSTimer scheduledTimerWithTimeInterval:SKIP_INTERVAL target:self selector:@selector(rewind) userInfo:player repeats:YES];
*/
}
- (IBAction)rewButtonReleased:(UIButton *)sender
{
/*
if (rewTimer) [rewTimer invalidate];
rewTimer = nil;
*/
}
- (IBAction)ffwButtonPressed:(UIButton *)sender
{
/*
if (ffwTimer) [ffwTimer invalidate];
ffwTimer = [NSTimer scheduledTimerWithTimeInterval:SKIP_INTERVAL target:self selector:@selector(ffwd) userInfo:player repeats:YES];
*/
}
- (IBAction)ffwButtonReleased:(UIButton *)sender
{
/*
if (ffwTimer) [ffwTimer invalidate];
ffwTimer = nil;
*/
}
- (IBAction)volumeSliderMoved:(UISlider *)sender
{
self.player.volume = [sender value];
}
- (IBAction)progressSliderMoved:(UISlider *)sender
{
self.player.currentTime = sender.value;
[self updateCurrentTimeForPlayer:self.player];
}
#pragma mark AudioSession handlers
/**
void RouteChangeListener( void * inClientData,
AudioSessionPropertyID inID,
UInt32 inDataSize,
const void * inData)
{
avTouchController* This = (avTouchController*)inClientData;
if (inID == kAudioSessionProperty_AudioRouteChange) {
CFDictionaryRef routeDict = (CFDictionaryRef)inData;
NSNumber* reasonValue = (NSNumber*)CFDictionaryGetValue(routeDict, CFSTR(kAudioSession_AudioRouteChangeKey_Reason));
int reason = [reasonValue intValue];
if (reason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) {
[This pausePlaybackForPlayer:This.player];
}
}
}*/
#pragma mark AVAudioPlayer delegate methods
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)p successfully:(BOOL)flag
{
if (flag == NO)
NSLog(@"Playback finished unsuccessfully");
[p setCurrentTime:0.];
if (self.inBackground)
{
[self updateViewForPlayerStateInBackground:p];
}
else
{
[self updateViewForPlayerState:p];
}
}
- (void)playerDecodeErrorDidOccur:(AVAudioPlayer *)p error:(NSError *)error
{
NSLog(@"ERROR IN DECODE: %@\n", error);
}
// we will only get these notifications if playback was interrupted
- (void)audioPlayerBeginInterruption:(AVAudioPlayer *)p
{
NSLog(@"Interruption begin. Updating UI for new state");
// the object has already been paused, we just need to update UI
if (self.inBackground)
{
[self updateViewForPlayerStateInBackground:p];
}
else
{
[self updateViewForPlayerState:p];
}
}
- (void)audioPlayerEndInterruption:(AVAudioPlayer *)p
{
NSLog(@"Interruption ended. Resuming playback");
[self startPlaybackForPlayer:p];
}
#pragma mark background notifications
- (void)registerForBackgroundNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(setInBackgroundFlag)
name:UIApplicationWillResignActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(clearInBackgroundFlag)
name:UIApplicationWillEnterForegroundNotification
object:nil];
}
- (void)setInBackgroundFlag
{
self.inBackground = true;
}
- (void)clearInBackgroundFlag
{
self.inBackground = false;
}
- (void)playAudio
{
// Move operation to new thread
dispatch_queue_t playAudiofile = dispatch_queue_create("play audiofile", NULL);
dispatch_async(playAudiofile, ^{
NSLog(@"Playing audiofile in new thread: %@", self.audiofile);
NSAssert(![self.audiofile isEqualToString:@""], @"audiofile must be specified.");
NSError *audioError;
NSString *soundFilePath = [[NSBundle mainBundle]pathForResource:self.audiofile ofType:@"mp3"];
NSAssert(soundFilePath != NULL, @"Sound File Not found");
NSURL *soundFileURL = [NSURL URLWithString:soundFilePath];
self.player = [[AVAudioPlayer alloc]initWithContentsOfURL:soundFileURL error:&audioError];
[self.player play];
});
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
frame #0: 0x020b4b54 libc++abi.dylib`__cxa_throw
frame #1: 0x0e215a41 AudioCodecs`ACBaseCodec::GetProperty(unsigned long, unsigned long&, void*) + 757
frame #2: 0x0e237618 AudioCodecs`ACMP4AACBaseDecoder::GetProperty(unsigned long, unsigned long&, void*) + 2458
frame #3: 0x0e235b83 AudioCodecs`ACMP4AACLowComplexityDecoder::GetProperty(unsigned long, unsigned long&, void*) + 565
frame #4: 0x0e28d4b4 AudioCodecs`GetProperty(void*, unsigned long, unsigned long*, void*) + 47
frame #5: 0x001347a8 AudioToolbox`AudioCodecGetProperty + 88
frame #6: 0x000392db AudioToolbox`CodecConverter::CheckInitialize(void const*, unsigned long) + 523
frame #7: 0x00038f34 AudioToolbox`CodecConverter::CodecConverter(OpaqueAudioComponent*&, OpaqueAudioComponentInstance*, StreamDescPair const&, StreamDescPair const&, bool, AudioConverterPrimeInfo const&) + 676
frame #8: 0x00038c7e AudioToolbox`CodecConverter::CodecConverter(OpaqueAudioComponent*&, OpaqueAudioComponentInstance*, StreamDescPair const&, StreamDescPair const&, bool, AudioConverterPrimeInfo const&) + 62
frame #9: 0x0003ddf7 AudioToolbox`CodecDecoderFactory::BuildCodecConverterChain(StreamDescPair const&, ChainBuildSettings const&, AudioConverterChain*, PCMConverterFactory*) + 631
frame #10: 0x0002647c AudioToolbox`ConverterRegistry::CreateConverter(StreamDescPair const&, AudioConverterChain**, unsigned long, AudioClassDescription const*) + 204
frame #11: 0x00019ba0 AudioToolbox`_AudioConverterNewInternal + 352
frame #12: 0x00060a00 AudioToolbox`AudioQueueObject::ConverterConnection::BuildConverter() + 416
frame #13: 0x000607e2 AudioToolbox`AudioQueueObject::ConverterConnection::ConverterConnection(AudioQueueObject&, long&) + 130
frame #14: 0x000620bc AudioToolbox`AudioQueueObject::IONodeConnection::GetConverterConnection_Init(long&) + 60
frame #15: 0x00065803 AudioToolbox`AudioQueueObject::SetProperty(unsigned long, CADeserializer&) + 1123
frame #16: 0x0008c44a AudioToolbox`AQServer_SetProperty + 106
frame #17: 0x00092276 AudioToolbox`AudioQueueSetProperty + 374
frame #18: 0x004c1d2b AVFoundation`AVAudioPlayerCpp::allocAudioQueue() + 683
frame #19: 0x004c13be AVFoundation`AVAudioPlayerCpp::prepareToPlayQueue() + 26
frame #20: 0x004bfebe AVFoundation`AVAudioPlayerCpp::prepareToPlay() + 84
frame #21: 0x004129f7 AVFoundation`-[AVAudioPlayer prepareToPlay] + 59
frame #22: 0x00006b7e SteinerAudio`-[AudioPlayerViewController viewDidLoad](self=0x07ad3cf0, _cmd=0x00b98a77) + 3694 at AudioPlayerViewController.mm:160
frame #23: 0x006c71c7 UIKit`-[UIViewController loadViewIfRequired] + 536
frame #24: 0x006c7232 UIKit`-[UIViewController view] + 33
frame #25: 0x006c74da UIKit`-[UIViewController contentScrollView] + 36
frame #26: 0x006de8e5 UIKit`-[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 36
frame #27: 0x006de9cb UIKit`-[UINavigationController _layoutViewController:] + 43
frame #28: 0x006dec76 UIKit`-[UINavigationController _updateScrollViewFromViewController:toViewController:] + 254
frame #29: 0x006ded71 UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 72
frame #30: 0x006df89b UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 386
frame #31: 0x006dfe93 UIKit`-[UINavigationController pushViewController:transition:forceImmediate:] + 1030
frame #32: 0x006dfa88 UIKit`-[UINavigationController pushViewController:animated:] + 62
frame #33: 0x00a3be63 UIKit`-[UIStoryboardPushSegue perform] + 1111
frame #34: 0x00a2db99 UIKit`-[UIStoryboardSegueTemplate _perform:] + 174
frame #35: 0x00a2dc14 UIKit`-[UIStoryboardSegueTemplate perform:] + 115
frame #36: 0x00695249 UIKit`-[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1134
frame #37: 0x006954ed UIKit`-[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 201
frame #38: 0x0109f5b3 Foundation`__NSFireDelayedPerform + 380
frame #39: 0x0199f376 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
frame #40: 0x0199ee06 CoreFoundation`__CFRunLoopDoTimer + 534
frame #41: 0x01986a82 CoreFoundation`__CFRunLoopRun + 1810
frame #42: 0x01985f44 CoreFoundation`CFRunLoopRunSpecific + 276
frame #43: 0x01985e1b CoreFoundation`CFRunLoopRunInMode + 123
frame #44: 0x028557e3 GraphicsServices`GSEventRunModal + 88
frame #45: 0x02855668 GraphicsServices`GSEventRun + 104
frame #46: 0x005e5ffc UIKit`UIApplicationMain + 1211
frame #47: 0x0000237d SteinerAudio`main(argc=1, argv=0xbffff3a0) + 141 at main.m:16
最佳答案
在 XCode 中禁用 C++/所有异常断点。或者编辑断点并将其设置为 objectiveC。
关于ios - AVAudioPlayer 在 iOS 设备上运行,在模拟器中崩溃。我应该担心吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17259902/
我正在尝试暂停 AVAudioPlayer如果当前正在播放。当我调试我的代码并检查时 AVAudioPlayer ,我看是分配的。当我尝试访问它的方法/属性(即 myAudioPlayer isPla
在我的应用程序中,我有 52 mp3,当我加载我的 View Controller 时,我以这种方式分配所有 52 mp3: NSString *pathFrase1 = [NSString stri
我在哪里可以找到 AVAudioPlayer 中所有支持的音频格式的列表?我试图在文档中找到有关它的任何信息,但我做不到。谢谢! 最佳答案 根据documentation of AVAudioPlay
我正在使用AVAssetReader读取ipod库 Assets 音频数据并渲染波形图像。这是使用我在对this question的回答中描述的代码进行的 这有时是在AVAudioPlayer实例播放
我正在创建和播放 AVAudioPlayer 如下: playerOne = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: path)
我被困在一些与 AVAudioPlayer 相关的奇怪内存泄漏问题上,在尝试了所有想到的东西后我需要帮助。 这是问题的简短描述 - 代码紧随其后。 我初始化我的播放器并开始无限循环播放音轨(无限循环或
我在使用 AVAudioPlayer 播放某些文件时遇到问题。当我尝试播放某个 m4a 时,效果很好。它也适用于我尝试过的 mp3。然而,无论我尝试播放它们的顺序如何,它每次都会在一个特定的 mp3
我会保持简短和甜蜜 - 在我为自己购买 iPhone 开发者计划之前,我正在构建一个应用程序只是为了练习。 我正在尝试 AVFoundation.framework,但一直遇到一个错误,该错误只会让我
场景如下...... 使用 AVAudioPlayer 播放背景 mp3, 在播放背景音乐时使用 AVPlayer 播放视频(无音频视频), 现在,如果尝试通过设备静音将音频静音,背景音频不会静音,
我有一个简单的问题:我正在将 mp3 文件加载到 NSData 对象中,然后在游戏中使用 AVAudioPlayer 来播放它。大约每隔一秒,帧速率就会下降,您可以看到屏幕上出现卡顿现象。这并不是一个
我喜欢更新现有的 iPhone 应用程序,该应用程序使用 AudioQueue 来播放音频文件。电平(peakPowerForChannel、averagePowerForChannel)从 0.0f
我得到了以下代码: - (id)init { if (self = [super init]) { UInt32 sessionCategory = kAudioSession
当我打开UIImagePickerController时,我可以显示设备的相机输入流。 但是当我使用 [player play] 播放 AVAudioPlayer 时,相机会停止工作。 我该如何处理这
我在使用 AVAudioPlayer 时遇到问题,我想重置当前正在播放的播放器并再次播放。 我尝试了以下方法,但没有成功: 声音播放一次,但第二次我选择按钮时它停止声音,第三次再次启动声音。 //St
所以我刚刚注意到,在我的 iPod Touch 上,当我的应用程序触发使用 AVAudioPlayer 播放的短 wav 文件时,音乐会暂停。这是正常的吗? 我找不到任何对此的引用,似乎会在某处注明。
我想控制AVAudioplayer中音频的播放速度。这可能吗?如果是这样,你会怎么做? 最佳答案 现在可以更改播放速度。 示例代码: player = [[AVAudioPlayer alloc] i
我只是想知道你如何重复 AVAudioPlayer? 最佳答案 将属性 numberOfLoops 设置为 -1,它将进入无限循环。 关于iphone - 如何重复播放 AVAudioPlayer?,
我有一个 AVAudioPlayer 正在播放一些音频(废话!) 当用户按下按钮时启动音频。当他们释放它时,我希望音频淡出。 我正在使用界面构建器...所以我尝试连接“touch up inside”
我有一个带有两个按钮的 AVAudioPlayer:播放和停止。 播放时播放按钮隐藏,反之亦然。 问题是当我尝试按下停止按钮时发生崩溃,就在播放结束时,在调用方法“audioPlayerDidFini
我观察到的奇怪的行为与AVAudioPlayer工作时 以下是代码: AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContent
我是一名优秀的程序员,十分优秀!