{"id":584,"date":"2018-02-23T23:40:12","date_gmt":"2018-02-23T15:40:12","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/ios%e9%9f%b3%e9%a2%91%e5%92%8c%e8%a7%86%e9%a2%91audio-video\/"},"modified":"2018-02-23T23:40:12","modified_gmt":"2018-02-23T15:40:12","slug":"ios%e9%9f%b3%e9%a2%91%e5%92%8c%e8%a7%86%e9%a2%91audio-video","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=584","title":{"rendered":"iOS\u97f3\u9891\u548c\u89c6\u9891(Audio &#038; Video)"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>IOS\u97f3\u9891\u548c\u89c6\u9891(Audio &amp; Video)<\/h1>\n<hr>\n<h3>\u7b80\u4ecb<\/h3>\n<p>\u97f3\u9891\u548c\u89c6\u9891\u5728\u6700\u65b0\u7684\u8bbe\u5907\u4e2d\u9887\u4e3a\u5e38\u89c1\u3002<\/p>\n<p>\u5c06iosAVFoundation.framework\u548cMediaPlayer.framework\u6dfb\u52a0\u5230Xcode\u9879\u76ee\u4e2d\uff0c\u53ef\u4ee5\u8ba9IOS\u652f\u6301\u97f3\u9891\u548c\u89c6\u9891(Audio &amp; Video)\u3002<\/p>\n<h3>\u5b9e\u4f8b\u6b65\u9aa4<\/h3>\n<p>1\u3001\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684View based application<\/p>\n<p>2\u3001\u9009\u62e9\u9879\u76ee\u6587\u4ef6\u3001\u9009\u62e9\u76ee\u6807\uff0c\u7136\u540e\u6dfb\u52a0AVFoundation.framework\u548cMediaPlayer.framework<\/p>\n<p>3\u3001\u5728ViewController.xib\u4e2d\u6dfb\u52a0\u4e24\u4e2a\u6309\u94ae\uff0c\u521b\u5efa\u4e00\u4e2a\u7528\u4e8e\u5206\u522b\u64ad\u653e\u97f3\u9891\u548c\u89c6\u9891\u7684\u52a8\u4f5c\uff08action\uff09<\/p>\n<p>4\u3001\u66f4\u65b0ViewController.h,\u5982\u4e0b\u6240\u793a<\/p>\n<pre>\n#import &lt;UIKit\/UIKit.h&gt;\n#import &lt;AVFoundation\/AVFoundation.h&gt;\n#import &lt;MediaPlayer\/MediaPlayer.h&gt;\n\n@interface ViewController : UIViewController\n{\n    AVAudioPlayer *audioPlayer;\n    MPMoviePlayerViewController *moviePlayer;\n    \n}\n-(IBAction)playAudio:(id)sender;\n-(IBAction)playVideo:(id)sender;\n@end\n<\/pre>\n<p>5\u3001\u66f4\u65b0ViewController.m\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre>\n#import \"ViewController.h\"\n\n@interface ViewController ()\n\n@end\n\n@implementation ViewController\n\n- (void)viewDidLoad\n{\n    [super viewDidLoad];\n}\n\n- (void)didReceiveMemoryWarning\n{\n   [super didReceiveMemoryWarning];\n   \/\/ Dispose of any resources that can be recreated.\n}\n-(IBAction)playAudio:(id)sender{\n   NSString *path = [[NSBundle mainBundle]\n   pathForResource:@\"audioTest\" ofType:@\"mp3\"];\n   audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:\n   [NSURL fileURLWithPath:path] error:NULL];\n   [audioPlayer play];\n}\n-(IBAction)playVideo:(id)sender{\n   NSString *path = [[NSBundle mainBundle]pathForResource:\n   @\"videoTest\" ofType:@\"mov\"];\n   moviePlayer = [[MPMoviePlayerViewController \n   alloc]initWithContentURL:[NSURL fileURLWithPath:path]];\n   [self presentModalViewController:moviePlayer animated:NO];\n}\n@end\n<\/pre>\n<h3>\u6ce8\u610f\u9879<\/h3>\n<p>\u9700\u8981\u6dfb\u52a0\u97f3\u9891\u548c\u89c6\u9891\u6587\u4ef6\uff0c\u4ee5\u786e\u4fdd\u83b7\u5f97\u9884\u671f\u7684\u8f93\u51fa<\/p>\n<h3>\u8f93\u51fa<\/h3>\n<p>\u8fd0\u884c\u8be5\u7a0b\u5e8f\uff0c\u5f97\u5230\u7684\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-full\" alt=\"AudioVideo_Output\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/AudioVideo_Output.jpg\" width=\"250\" height=\"496\" data-pinit=\"registered\"><\/p>\n<p>\u5f53\u6211\u4eec\u70b9\u51fb play video(\u64ad\u653e\u89c6\u9891)\u663e\u793a\u5982\u4e0b\uff1a\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"attachment-full\" alt=\"video_Output\" src=\"http:\/\/www.runoob.com\/wp-content\/uploads\/2013\/11\/video_Output.jpg\" width=\"250\" height=\"490\" data-pinit=\"registered\"><\/p>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">IOS\u97f3\u9891\u548c\u89c6\u9891(Audio &amp; Video) \u7b80\u4ecb \u97f3\u9891\u548c\u89c6\u9891\u5728\u6700\u65b0\u7684\u8bbe\u5907\u4e2d\u9887\u4e3a&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=584\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,26],"tags":[74,93],"class_list":["post-584","post","type-post","status-publish","format-standard","hentry","category-ios","category-mobile","tag-ios","tag-mobile","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=584"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/584\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}