IOS音頻和視頻(Audio & Video)
IOS音頻和視頻(Audio & Video)
簡介
音頻和視頻在**的設備中頗為常見。
將iosAVFoundation.framework和MediaPlayer.framework添加到Xcode項目中,可以讓IOS支持音頻和視頻(Audio & Video)。
我贏職場IOS音頻和視頻教程的學習:
實例步驟
1、創建一個簡單的View based application
2、選擇項目文件、選擇目標,然后添加AVFoundation.framework和MediaPlayer.framework
3、在ViewController.xib中添加兩個按鈕,創建一個用于分別播放音頻和視頻的動作(action)
4、更新ViewController.h,如下所示
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController : UIViewController{
AVAudioPlayer *audioPlayer;
MPMoviePlayerViewController *moviePlayer;
}
-(IBAction)playAudio:(id)sender;
-(IBAction)playVideo:(id)sender;
@end
5、更新ViewController.m,如下所示
#import ViewController.h
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)playAudio:(id)sender{
NSString *path = [[NSBundle mainBundle]
pathForResource:@ audioTest ofType:@ mp3 ];
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:
[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer play];
}
-(IBAction)playVideo:(id)sender{
NSString *path = [[NSBundle mainBundle]pathForResource:
@ videoTest ofType:@ mov ];
moviePlayer = [[MPMoviePlayerViewController
alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
[self presentModalViewController:moviePlayer animated:NO];
}
@end
注意項
需要添加音頻和視頻文件,以確保獲得預期的輸出
學習鏈接:
http://www.wyzc.com/ios/?tg=5009295340
學習交流群:317140762 |
劉老師:聯系電話:010-82168774-8005
手機:18201568921
|
友情提示:
信息由用戶自行發布,采用請謹慎,我們鼓勵您當面交易。如有不符合法規或造成侵權,請及時通知本站更正或刪除,具體聯系方式見頁面底部聯系我們。名站在線只為傳遞信息,我們不做任何雙方證明,也不承擔任何法律責任。 信息轉載,請標明來源于www.www.9896525.com ,謝謝。 |
當前頁在本站[名站在線]7天內點擊次數(點擊次數為零的日期不顯示): |
信息評估: |
(還沒有網友對該信息作出評估,你想為該信息提供第一個評估嗎?) |
|
|
|