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

iPhone視頻播放項目開發(fā)

移動開發(fā) iOS
本文介紹的iPhone視頻播放項目開發(fā),本文通過詳細(xì)的代碼來實現(xiàn)iphone中視頻的播放。來看詳細(xì)內(nèi)容。

iPhone視頻播放項目開發(fā)是本文要介紹的內(nèi)容,我感覺iphone視頻的播放一直是一個軟肋,我在之前因為做了一個iphone視頻的項目所以其有所研究。 大家應(yīng)該知道!3.2后iphone視頻方面增加了和多通知!這在之前是沒有的,于是多了很多功能,我感覺這方面還是不錯的!

下面一步一步的講講視頻

首先展示一下代碼:

  1. -(void) playMovieWithSDK: (NSURL*) movieUrl  
  2. {  
  3. if ([[[UIDevice currentDevice] systemVersion] doubleValue] > 3.2)  
  4. {  
  5. self.view.backgroundColor = [UIColor redColor];  
  6. mSdk4Player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieUrl];  
  7. mSdk4Player.navigationController.navigationBar.tag = 1003;  
  8. [self.navigationController.navigationBar setNeedsDisplay];  
  9. if (mSdk4Player)  
  10. {  
  11. mSdk4Player.moviePlayer.shouldAutoplay = YES;  
  12. [self presentMoviePlayerViewControllerAnimated:mSdk4Player];  
  13. mSdk4Player.moviePlayer.scalingModeMPMovieScalingModeAspectFit;    
  14. [mSdk4Player.moviePlayer play];  
  15. [mSdk4Player release];  
  16. backgroundIamge = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];  
  17. [backgroundIamge setImage:[UIImage imageNamed:@"playBg.png"]];  
  18. [mSdk4Player.view addSubview:backgroundIamge];  
  19. backgroundIamge.hidden = YES;  
  20. UIDevice *device = [UIDevice currentDevice];  
  21. if (device.orientation == UIInterfaceOrientationPortrait || device.orientation == UIInterfaceOrientationPortraitUpsideDown)  
  22. {  
  23. backgroundIamge.center = CGPointMake(160, 240);  
  24. }  
  25. else if(device.orientation == UIInterfaceOrientationLandscapeLeft||device.orientation == UIInterfaceOrientationLandscapeRight)  
  26. {  
  27. backgroundIamge.center = CGPointMake(240, 160);  
  28. }  
  29. else   
  30. {  
  31. backgroundIamge.center = CGPointMake(160, 240);  
  32. }  
  33. [[NSNotificationCenter defaultCenter]  
  34. addObserver: self  
  35. selector: @selector(movieFinishedCallback:)  
  36. name: MPMoviePlayerPlaybackDidFinishNotification  
  37. object: mSdk4Player.moviePlayer];  
  38. [[NSNotificationCenter defaultCenter]  
  39. addObserver: self  
  40. selector: @selector(movieReadyToPlay:)  
  41. name: MPMovieMediaTypesAvailableNotification  
  42. object: nil];  
  43. [[NSNotificationCenter defaultCenter]  
  44. addObserver: self  
  45. selector: @selector(addMoviePicture:)  
  46. name: MPMoviePlayerNowPlayingMovieDidChangeNotification  
  47. object: nil];  
  48. [[NSNotificationCenter defaultCenter]  
  49. addObserver: self  
  50. selector: @selector(changeAddedPictureSize:)  
  51. name: UIApplicationWillChangeStatusBarOrientationNotification  
  52. object: nil];  
  53. }  
  54. // backgroundIamge.center = CGPointMake(240, 160);  
  55. }  
  56. else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) //sdk 3.0 播放器   
  57. {  
  58. MPMoviePlayerController* mSdk3player = [[MPMoviePlayerController alloc] initWithContentURL: movieUrl];  
  59. mSdk3player.scalingMode = MPMovieScalingModeAspectFit;  
  60. [[NSNotificationCenter defaultCenter]  
  61. addObserver: self  
  62. selector: @selector(movieFinishedCallback:)  
  63. name: MPMoviePlayerPlaybackDidFinishNotification  
  64. object: mSdk3player];  
  65. [mSdk3player play];  
  66. }  
  67. }  
  68. //播放電影  
  69. -(void) playMovie  
  70. {  
  71. NSURL *movieUrl = [NSURL URLWithString:_movieString];  
  72. if([movieUrl scheme])  
  73. {  
  74. [self playMovieWithSDK:movieUrl];  
  75. //此處的將最新的movie提到最上面是在數(shù)據(jù)庫中進行的  
  76. [self checkHisState];  
  77. [self setHistory];  
  78. }  
  79. else   
  80. {  
  81. UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"" message: @"" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil];  
  82. [alert show];  
  83. [alert release];  
  84. }  
  85. }  
  86. // 通知釋放播放器  
  87. -(void) movieFinishedCallback:(NSNotification*)aNotification  
  88. {  
  89. MPMoviePlayerController* theMovie=[aNotification object];  
  90.     [[NSNotificationCenter defaultCenter] removeObserver:self  
  91.                                                     name:MPMoviePlayerPlaybackDidFinishNotification  
  92.                                                   object:theMovie];  
  93. _detailViewController = [[DetailViewController alloc]initWithNibName:nil bundle:nil messageData:_message index:index];  
  94. [_detailViewController.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""]];  
  95. [self.navigationController pushViewController:_detailViewController animated:NO];  
  96. }  
  97. -(void) addMoviePicture:(NSNotification*)aNotification  
  98. {  
  99. backgroundIamge.hidden = NO;   
  100. }  
  101. -(void) movieReadyToPlay:(NSNotification*)aNotification  
  102. {  
  103. backgroundIamge.hidden = YES;  
  104.     [[NSNotificationCenter defaultCenter] removeObserver:self  
  105.                                                     name:MPMovieMediaTypesAvailableNotification  
  106.                                                   object:nil];  
  107. }  
  108. -(void) changeAddedPictureSize:(NSNotification*)aNotification  
  109. {  
  110. UIDevice *device = [UIDevice currentDevice];  
  111. if (device.orientation == UIInterfaceOrientationPortrait || device.orientation == UIInterfaceOrientationPortraitUpsideDown)  
  112. {  
  113. backgroundIamge.center = CGPointMake(160, 240);  
  114. }  
  115. else if(device.orientation == UIInterfaceOrientationLandscapeLeft||device.orientation == UIInterfaceOrientationLandscapeRight)  
  116. {  
  117. backgroundIamge.center = CGPointMake(240, 160);  
  118. }  
  119. else   
  120. {  
  121. backgroundIamge.center = CGPointMake(160, 240);  
  122. }  

通過以上代碼我想大家應(yīng)該對iphone視頻的播放有所了解了!我重點說幾點吧:

1、我在播放視頻的時候加上了對手機版本的判斷,這是因為很多通知在3.2 之前的版本是不能用的。

2、在代碼中我加入了大量的通知,我一個一個說來:

(1) [[NSNotificationCenter defaultCenter]

  1. addObserver: self  
  2. selector: @selector(movieFinishedCallback:)  
  3. name: MPMoviePlayerPlaybackDidFinishNotification  
  4. object: mSdk4Player.moviePlayer]; 

上面這個通知是在視頻播放完的時候觸發(fā)的,就是說你想在播放完視頻的時候想做什么工作可以在方法中寫入。

(2) [[NSNotificationCenter defaultCenter]

  1. addObserver: self  
  2. selector: @selector(movieReadyToPlay:)  
  3. name: MPMovieMediaTypesAvailableNotification  
  4. object: nil]; 

上面這個通知是在準(zhǔn)備播放視頻觸發(fā)的。

(3) [[NSNotificationCenter defaultCenter]

  1. addObserver: self  
  2. selector: @selector(addMoviePicture:)  
  3. name: MPMoviePlayerNowPlayingMovieDidChangeNotification  
  4. object: nil]; 

上面這個通知是在加載視頻之前還沒有播放視頻之前觸發(fā)的。

(4)[[NSNotificationCenter defaultCenter]

  1. addObserver: self  
  2. selector: @selector(changeAddedPictureSize:)  
  3. name: UIApplicationWillChangeStatusBarOrientationNotification  
  4. object: nil]; 

上面這個通知是設(shè)備發(fā)生重力變換的時候觸發(fā)的。

通過以上幾個通知基本上因該滿足一個不錯的,可觀賞性的視頻播放器了。大家可以試試!!

小結(jié):iPhone視頻播放項目開發(fā)的內(nèi)容介紹完了,希望本文對你有所幫助!

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-20 16:21:20

iPhone 視頻 播放器

2011-08-17 14:57:31

iPhone應(yīng)用視頻播放

2011-08-08 18:19:09

iPhone音頻播放

2011-08-08 10:23:41

iPhone 流播放 文件

2011-07-21 15:49:27

iPhone 模擬器 視頻

2011-08-09 14:42:07

iPhonePCM播放器

2011-08-17 16:12:20

iPhone應(yīng)用程序

2011-07-18 15:32:14

iPhone 錄音 播放

2011-07-06 17:53:40

iPhone SDK Xcode

2011-07-22 15:59:15

iPhone 聲音 文件

2011-08-02 16:58:15

iPhone AVAudioPla 音頻播放

2011-07-27 09:50:31

iPhone AVAudioPla 音頻

2011-07-08 20:32:57

iPhone midi

2011-07-25 18:02:51

iPhone LibFetion 移植

2011-02-01 17:32:38

App StoreiPhone手機游戲

2021-10-18 14:57:25

鴻蒙HarmonyOS應(yīng)用

2009-04-06 08:26:14

iphone蘋果移動OS

2011-07-06 17:34:47

iPhone

2011-07-08 10:58:47

2011-08-10 15:48:10

iPhone網(wǎng)絡(luò)
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 国产激情视频在线观看 | 亚洲看片网站 | 一级片在线视频 | 国产一区二区欧美 | 成人精品一区二区 | 啪一啪在线视频 | 日韩精品在线一区 | 91亚洲精品在线 | 福利精品在线观看 | 99re免费 | 综合色播 | 久久午夜精品福利一区二区 | 91精品在线播放 | 欧美性生交大片免费 | a天堂在线| 精品国产一区二区在线 | 国产线视频精品免费观看视频 | 精品国产不卡一区二区三区 | 精品视频在线观看 | 国产一二三区精品视频 | 五月激情久久 | 99精品视频免费观看 | 亚洲一区二区在线视频 | 亚洲毛片在线观看 | 精品一区二区在线看 | 国产欧美精品一区二区三区 | 国产精品久久久久一区二区三区 | 亚洲一级视频在线 | 国产精品福利视频 | 日本人做爰大片免费观看一老师 | 免费黄色的视频 | 九一国产精品 | 91精品国产综合久久久久久漫画 | 99reav | 欧美一区二区三区在线免费观看 | 亚洲电影免费 | 国产在线一区二区三区 | 久久免费精品 | 中文字幕国产精品 | chinese中国真实乱对白 | 亚洲一区精品视频 |