可能重复简单的方法:
Is it possible to play sounds without stopping iPod music?播放声音没有停止音乐iPhone的SDK
有没有播放声音没有停止音乐的简单方法?我试图制作一个节拍器应用程序,如果你有任何建议,他们将不胜感激。
可能重复简单的方法:
Is it possible to play sounds without stopping iPod music?播放声音没有停止音乐iPhone的SDK
有没有播放声音没有停止音乐的简单方法?我试图制作一个节拍器应用程序,如果你有任何建议,他们将不胜感激。
另一种解决方案:创建一个播放器类来包装初始化(使用AVFoundation.framework)。
来源:
#import "MyAVAudioPlayer.h"
@implementation MyAVAudioPlayer
-(id)initWithFile:(NSString*)strFile
{
NSError *err;
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/"];
resourcePath = [resourcePath stringByAppendingString:strFile];
self = [super initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath]
error:&err];
if(err)
{
NSLog(@"Loading of %@ Failed with reason: %@", strFile,
[err localizedDescription]);
}
else
{
NSLog(@"Loaded %@", strFile);
[self prepareToPlay];
}
return self;
}
@end
页眉:
#import <AVFoundation/AVFoundation.h>
@interface MyAVAudioPlayer : AVAudioPlayer
{
}
-(id)initWithFile:(NSString*)strFile;
@end
用法:
MyAVAudioPlayer *player = [[MyAVAudioPlayer alloc] initWithFile:@"yoursound.mp3"];
[player play]
你说的是播放声音,而不从iPod /音乐应用中断的音乐?如果是这样,您需要配置音频会话类别以允许与kAudioSessionProperty_OverrideCategoryMixWithOthers
属性混合。
有关示例代码,请参阅Is it possible to play sounds without stopping iPod music?。