大佬教程收集整理的这篇文章主要介绍了objective-c – Xcode中的循环音频,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的代码.m
CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef soundFileURLRef; soundFileURLRef = CFBundleCopyresourceURL(mainBundle,(CFStringRef) @"ar4",CFSTR ("wav"),null); UInt32 soundID; AudioservicesCreateSystemSoundID (soundFileURLRef,&soundID); AudioservicesPlaySystemSound (soundID);
我想我需要把这样的东西放进去
numberOfLoops = -1;
NSString* resourcePath = [[NSBundle mainBundle] resourcePath]; resourcePath = [resourcePath StringByAppendingString:@"/YOURMUSICNAME.mp3"]; NSLog(@"Path to play: %@",resourcePath); NSError* err; //Initialize our player poinTing to the path to our resource player = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:resourcePath] error:&err]; if( err ){ //bail! NSLog(@"Failed with reason: %@",[err localizedDescription]); } else{ //set our delegate and begin playBACk player.delegate = self; [player play]; player.numberOfLoops = -1; player.currentTime = 0; player.volume = 1.0; }
然后,如果你想阻止它:
[player stop];
或暂停:
[player pause];
并将其导入头文件中:
#import <AVFoundation/AVFoundation.h>.
//.h并添加粗体部分:
@interface ViewController:UIViewController< AVAudioPlayerDelegate> {
AVAudioPlayer *player; } @property (nonatomic,retain) AVAudioPlayer *player;
//.m
@synthesize player;
以上是大佬教程为你收集整理的objective-c – Xcode中的循环音频全部内容,希望文章能够帮你解决objective-c – Xcode中的循环音频所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。