{"id":6996,"date":"2025-06-02T14:45:57","date_gmt":"2025-06-05T07:30:57","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6996"},"modified":"2025-06-05T14:45:57","modified_gmt":"2025-06-05T07:30:57","slug":"https-badgameshow-com-steven-174","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-174\/","title":{"rendered":"\u5982\u4f55\u5728 Swift \u4e2d\u5be6\u73fe\u5168\u87a2\u5e55\u8996\u983b\u64ad\u653e\uff1a2025 \u6700\u65b0\u6559\u5b78"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, \u5168\u87a2\u5e55\u64ad\u653e\u8996\u983b, AVKit, iOS, macOS\"><\/p>\n<h2>\u7c21\u4ecb<\/h2>\n<p>Swift \u662f\u4e00\u7a2e\u7528\u65bc\u958b\u767c iOS \u548c macOS \u61c9\u7528\u7a0b\u5f0f\u7684\u5f37\u5927\u958b\u653e\u6e90\u4ee3\u78bc\u7a0b\u5f0f\u8a9e\u8a00\u3002\u96a8\u8457 2025 \u5e74\u7684\u6700\u65b0\u66f4\u65b0\uff0c\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 Swift \u4f86\u5be6\u73fe\u5168\u87a2\u5e55\u64ad\u653e\u8996\u983b\uff0c\u4e26\u63d0\u4f9b\u5b8c\u6574\u7684\u5be6\u4f5c\u7bc4\u4f8b\u53ca\u6700\u4f73\u5be6\u8e10\uff0c\u8b93\u60a8\u80fd\u5920\u8f15\u9b06\u4e0a\u624b\u3002<\/p>\n<h2>\u6e96\u5099\u5de5\u4f5c<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u78ba\u4fdd\u60a8\u5df2\u7d93\u5b89\u88dd\u4e86 <strong>AVKit<\/strong> \u6846\u67b6\u3002\u9019\u662f Apple \u63d0\u4f9b\u7684\u7528\u65bc\u64ad\u653e\u8996\u983b\u7684\u6846\u67b6\uff0c\u5b83\u80fd\u7c21\u5316\u8996\u983b\u64ad\u653e\u7684\u904e\u7a0b\u3002\u60a8\u53ef\u4ee5\u5728 Xcode \u7684\u5c08\u6848\u4e2d\u8f15\u9b06\u5f15\u5165\u6b64\u6846\u67b6\u3002<\/p>\n<h2>\u5be6\u4f5c\u6b65\u9a5f<\/h2>\n<h3>1. \u5275\u5efa AVPlayerViewController<\/h3>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5275\u5efa\u4e00\u500b <strong>AVPlayerViewController<\/strong> \u5c0d\u8c61\uff0c\u9019\u500b\u5c0d\u8c61\u5c07\u7528\u65bc\u986f\u793a\u548c\u63a7\u5236\u8996\u983b\u64ad\u653e\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let playerViewController = AVPlayerViewController()<\/code><\/pre>\n<h3>2. \u8a2d\u7f6e AVPlayer<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5275\u5efa\u4e00\u500b <strong>AVPlayer<\/strong> \u5c0d\u8c61\uff0c\u4e26\u5c07\u5176\u6307\u5411\u8981\u64ad\u653e\u7684\u8996\u983b URL\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let videoURL = URL(string: \"https:\/\/example.com\/video.mp4\")!\nlet player = AVPlayer(url: videoURL)<\/code><\/pre>\n<h3>3. \u5c07 AVPlayer \u8a2d\u7f6e\u5230 AVPlayerViewController<\/h3>\n<p>\u5c07\u525b\u525b\u5275\u5efa\u7684 <strong>AVPlayer<\/strong> \u5c0d\u8c61\u8ce6\u503c\u7d66 <strong>AVPlayerViewController<\/strong> \u7684 <strong>player<\/strong> \u5c6c\u6027\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">playerViewController.player = player<\/code><\/pre>\n<h3>4. \u8a2d\u7f6e\u5168\u87a2\u5e55\u986f\u793a<\/h3>\n<p>\u70ba\u4e86\u8b93\u8996\u983b\u4ee5\u5168\u87a2\u5e55\u7684\u65b9\u5f0f\u64ad\u653e\uff0c\u9700\u8981\u5c07 <strong>AVPlayerViewController<\/strong> \u7684 <strong>modalPresentationStyle<\/strong> \u5c6c\u6027\u8a2d\u7f6e\u70ba <strong>.fullScreen<\/strong>\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">playerViewController.modalPresentationStyle = .fullScreen<\/code><\/pre>\n<h3>5. \u64ad\u653e\u8996\u983b<\/h3>\n<p>\u6700\u5f8c\uff0c\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u5448\u73fe <strong>AVPlayerViewController<\/strong>\uff0c\u4e26\u958b\u59cb\u64ad\u653e\u8996\u983b\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">present(playerViewController, animated: true, completion: {\n    player.play()\n})<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5982\u679c\u8996\u983b\u7121\u6cd5\u64ad\u653e\uff0c\u8acb\u6aa2\u67e5\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u78ba\u8a8d\u8996\u983b URL \u662f\u5426\u6b63\u78ba\u4e26\u53ef\u8a2a\u554f\u3002<\/li>\n<li>\u78ba\u4fdd\u5df2\u6b63\u78ba\u5f15\u5165 AVKit \u6846\u67b6\u3002<\/li>\n<li>\u6aa2\u67e5\u8a2d\u5099\u7684\u97f3\u91cf\u8a2d\u7f6e\uff0c\u78ba\u4fdd\u672a\u975c\u97f3\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u5168\u87a2\u5e55\u64ad\u653e\uff0c\u60a8\u9084\u53ef\u4ee5\u8003\u616e\u5728\u61c9\u7528\u4e2d\u589e\u52a0\u4ee5\u4e0b\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\u6dfb\u52a0\u64ad\u653e\u63a7\u5236\u6309\u9215\uff08\u64ad\u653e\u3001\u66ab\u505c\u3001\u5feb\u9032\u7b49\uff09\u3002<\/li>\n<li>\u5be6\u73fe\u8996\u983b\u7684\u7e2e\u653e\u548c\u65cb\u8f49\u529f\u80fd\u3002<\/li>\n<li>\u4f7f\u7528 AVPlayer \u7684\u76e3\u807d\u5668\u4f86\u76e3\u63a7\u64ad\u653e\u9032\u5ea6\u548c\u72c0\u614b\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5168\u87a2\u5e55\u64ad\u653e\u8996\u983b-\ud83d\udcf9_1675400229.886388.webp\" alt=\"Swift \u5168\u87a2\u5e55\u64ad\u653e\u8996\u983b\u7684\u622a\u5716\" title=\"Swift \u5168\u87a2\u5e55\u64ad\u653e\u8996\u983b\u622a\u5716\uff0c\u5c55\u793a\u4e86\u8996\u983b\u64ad\u653e\u4ecb\u9762\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>\u5e38\u898b\u554f\u984c\u89e3\u7b54 (Q&#038;A)<\/h2>\n<h3>Q1: \u5982\u4f55\u5728 Swift \u4e2d\u5be6\u73fe\u8996\u983b\u81ea\u52d5\u64ad\u653e\uff1f<\/h3>\n<p>A1: \u60a8\u53ef\u4ee5\u5728 <strong>present<\/strong> \u65b9\u6cd5\u7684 <strong>completion<\/strong> \u9589\u5305\u4e2d\u8abf\u7528 <strong>player.play()<\/strong> \u65b9\u6cd5\uff0c\u8b93\u8996\u983b\u5728\u986f\u793a\u5f8c\u81ea\u52d5\u64ad\u653e\u3002<\/p>\n<h3>Q2: AVPlayerViewController \u652f\u63f4\u54ea\u4e9b\u8996\u983b\u683c\u5f0f\uff1f<\/h3>\n<p>A2: AVPlayerViewController \u652f\u63f4\u591a\u7a2e\u8996\u983b\u683c\u5f0f\uff0c\u5305\u62ec MP4\u3001MOV \u548c M4V \u7b49\u5e38\u898b\u683c\u5f0f\u3002<\/p>\n<h3>Q3: \u5982\u4f55\u5728 AVPlayerViewController \u4e2d\u6dfb\u52a0\u81ea\u8a02\u63a7\u5236\u9805\uff1f<\/h3>\n<p>A3: \u82e5\u8981\u6dfb\u52a0\u81ea\u8a02\u63a7\u5236\u9805\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u81ea\u5b9a\u7fa9\u754c\u9762\uff0c\u4e26\u5c07\u5176\u8207 AVPlayer \u7684\u64ad\u653e\u72c0\u614b\u9032\u884c\u7d81\u5b9a\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u8a9e\u8a00\u4f86\u5be6\u73fe\u5168\u87a2\u5e55\u64ad\u653e\u8996\u983b\u7684\u529f\u80fd\uff0c\u4e26\u63d0\u4f9b\u7a0b\u5f0f\u78bc\u793a\u4f8b\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n","protected":false},"author":1,"featured_media":6994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[174,5],"tags":[173,9],"class_list":["post-6996","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5168\u87a2\u5e55\u64ad\u653e\u8996\u983b-\ud83d\udcf9_1675400229.886388.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1OQ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=6996"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6996\/revisions"}],"predecessor-version":[{"id":13315,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6996\/revisions\/13315"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6994"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}