成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iPhone應用 AVAudioPlayer播放音頻講解

移動開發 iOS
本文介紹的是iPhone應用 AVAudioPlayer播放音頻講解,主要介紹了使用AVAudioPlayer可以實現載入、播放、暫停、停止音頻,監控平均和峰值音量,來看詳細內容。

iPhone應用 AVAudioPlayer播放音頻講解是本文要介紹的內容,iPhone是媒體大師,其內建的iPod功能可輕松的處理音頻和視頻,下面我將對AVAudioPlayer這個音頻播放類詳細的介紹。使用AVAudioPlayer可以實現載入、播放、暫停、停止音頻,監控平均和峰值音量水平.

AVAudioPlayer處理音頻中斷

當用戶在音頻回放期間受到電話時,音頻會消失,出現這種情況時AVAudioPlayer委托接受audioPlayerBeginInterruption:回調,音頻會話暫時無效,并且暫停播放器。

如果用戶接聽電話,那么應用程序中止,而應用程序委托接受一個applicationWillResignActive:回調。當通話結束,應用程序重新啟動(利用applicationDidBecomeActive:回調)。如果用戶拒絕接聽電話那么將向委托發送audioPlayerBeginInterruption:回調。可以從此方法回復回放。

例子:

  1. #import <UIKit/UIKit.h> 
  2. #import <AVFoundation/AVFoundation.h> 
  3.  
  4. #define COOKBOOK_PURPLE_COLOR [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]  
  5. #define BARBUTTON(TITLE, SELECTOR)  [[[UIBarButtonItem alloc] initWithTitle:TITLE style:
  6. UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease]  
  7. #define SYSBARBUTTON(ITEM, TARGET, SELECTOR) [[[UIBarButtonItem alloc] 
  8. initWithBarButtonSystemItem:ITEM target:TARGET action:SELECTOR] autorelease]  
  9.  
  10. @interface TestBedViewController : UIViewController <AVAudioPlayerDelegate> 
  11. {  
  12.  AVAudioPlayer *player;  
  13. }  
  14. @property (retain) AVAudioPlayer *player;  
  15. @end  
  16.  
  17. @implementation TestBedViewController  
  18. @synthesize player;  
  19.  
  20. - (BOOL) prepAudio  
  21. {  
  22.  NSError *error;  
  23.  NSString *path = [[NSBundle mainBundle] pathForResource:@"MeetMeInSt.Louis1904" ofType:@"mp3"];  
  24.  if (![[NSFileManager defaultManager] fileExistsAtPath:path]) return NO;  
  25.    
  26.  // Initialize the player  
  27.  self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];  
  28.  selfself.player.delegate = self;  
  29.  if (!self.player)  
  30.  {  
  31.   NSLog(@"Error: %@", [error localizedDescription]);  
  32.   return NO;  
  33.  }  
  34.    
  35.  [self.player prepareToPlay];  
  36.  
  37.  return YES;  
  38. }  
  39.  
  40. - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag  
  41. {  
  42.  // just keep playing  
  43.  [self.player play];  
  44. }  
  45.  
  46. - (void)audioPlayerBeginInterruption:(AVAudioPlayer *)player  
  47. {  
  48.  // perform any interruption handling here  
  49.  printf("Interruption Detected\n");  
  50.  [[NSUserDefaults standardUserDefaults] setFloat:[self.player currentTime] forKey:@"Interruption"];  
  51. }  
  52.  
  53. - (void)audioPlayerEndInterruption:(AVAudioPlayer *)player  
  54. {  
  55.  // resume playback at the end of the interruption  
  56.  printf("Interruption ended\n");  
  57.  [self.player play];  
  58.    
  59.  // remove the interruption key. it won't be needed  
  60.  [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Interruption"];  
  61. }  
  62.  
  63. - (void) viewDidLoad  
  64. {  
  65.  self.navigationController.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;  
  66.  [self prepAudio];  
  67.  
  68.  // Check for previous interruption  
  69.  if ([[NSUserDefaults standardUserDefaults] objectForKey:@"Interruption"])  
  70.  {   
  71.   self.player.currentTime = [[NSUserDefaults standardUserDefaults] floatForKey:@"Interruption"];  
  72.   [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"Interruption"];  
  73.  }  
  74.    
  75.  // Start playback  
  76.  [self.player play];  
  77. }  
  78.  
  79. @end  
  80.  
  81. @interface TestBedAppDelegate : NSObject <UIApplicationDelegate> 
  82. @end  
  83.  
  84. @implementation TestBedAppDelegate  
  85. - (void)applicationDidFinishLaunching:(UIApplication *)application {   
  86.  UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  87.  UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[TestBedViewController alloc] init]];  
  88.  [window addSubview:nav.view];  
  89.  [window makeKeyAndVisible];  
  90. }  
  91. @end  
  92.  
  93. int main(int argc, char *argv[])  
  94. {  
  95.  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];  
  96.  int retVal = UIApplicationMain(argc, argv, nil, @"TestBedAppDelegate");  
  97.  [pool release];  
  98.  return retVal;  

小結:iPhone應用 AVAudioPlayer播放音頻講解的內容介紹完了,希望本文對你有所幫助!

責任編輯:zhaolei 來源: 互聯網
相關推薦

2011-08-02 16:58:15

iPhone AVAudioPla 音頻播放

2011-08-08 18:19:09

iPhone音頻播放

2011-08-17 14:57:31

iPhone應用視頻播放

2011-12-23 10:17:25

Android音樂編程管理音頻焦點

2011-07-20 15:58:58

iPhone 應用程序 生命周期

2011-05-18 15:50:26

UI設計iPhoneiOS

2012-12-24 14:48:14

ios

2013-04-08 09:46:23

iPhone開發音頻資料

2011-08-10 15:58:58

iPhone視頻

2021-07-09 09:24:41

鴻蒙HarmonyOS應用

2011-07-06 16:15:46

iPhone 圖片

2011-08-09 14:42:07

iPhonePCM播放器

2024-04-23 08:24:05

音頻Android播放

2014-09-11 10:33:06

Linux

2011-07-18 15:32:14

iPhone 錄音 播放

2011-08-22 11:49:20

iPhone文件系統NSFileManag

2011-07-29 13:27:48

iPhone 開發 Nib

2011-12-22 09:54:40

PhoneGap APMedia

2011-08-22 13:46:15

iPhone開發GameKit 藍牙

2020-02-20 20:51:09

FedoraLinux播放音樂
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美日产国产成人免费图片 | 日韩精品一区二区三区在线播放 | 久久免费观看视频 | 亚洲草草视频 | 狠狠干天天干 | 精品国产一区二区三区四区在线 | 综合久久综合久久 | 日韩av一区二区在线观看 | 综合久久久| 欧美人妇做爰xxxⅹ性高电影 | 精品欧美二区 | 国产99久久精品一区二区永久免费 | 欧美一级久久 | 免费在线观看成年人视频 | 美女天堂| 91精品国产综合久久久久久首页 | 精品一区二区三区不卡 | 欧美一区不卡 | 国产精品乱码一区二区三区 | 亚洲97 | 女同久久 | 国产精品久久久99 | 久久国产精品99久久久大便 | 老子午夜影院 | 国产成人精品综合 | 欧美黄色片在线观看 | 久久精品国产一区二区三区不卡 | 成人在线精品 | 亚洲综合视频 | 欧美黑人巨大videos精品 | 精品96久久久久久中文字幕无 | 久久精品色欧美aⅴ一区二区 | 国产专区在线 | 色综合天天综合网国产成人网 | 久久久久久久av | 日韩国产精品一区二区三区 | 人人种亚洲 | www免费视频 | 欧美精品一区二区在线观看 | 精品国产一区二区三区在线观看 | 亚洲免费观看视频 |