iOS 流媒體 基本使用 和方法注意

項目里面需要添加視頻方法 ? 我自定義 選用的是 avplayer ?沒選擇?MediaPlayer ?原因很簡單 , avplayer 會更容易擴展 ?有篇博客 也很好地說明了 使用avplayer的優越性

blog.csdn.net/think12/article/details/8549438
在iOS開發上,如果遇到需要播放影片,如開機動畫…,我們很習慣地會使用MediaPlayer來播放影片,因為很方便使用,所以就一直使用下去。但是 隨著客戶的要求越來越嚴苛,尤其是過場動畫或互動效果上的表現。所以如果在一些動畫中還挾帶影片一起運算,那勢必機器會跑不動。所以在iOS 4之後,我們可以使用AVPlayer這個類別來進行更細微的操作。備註:MediaPlayer的影片是放在UIView 裡面,而AVPlayer是放在AVPlayerLayer裡面,AVPlayerLayer是CALayer 的子類別。
使用MediaPlayer前,要記得加入MediaPlayer.framework及#import <MediaPlayer/MediaPlayer.h>
使用AVPlayer前,要記得加入AVFoundation.frameworkk及#import <AVFoundation/AVFoundation.h>
請參考以下的範例:
使用MediaPlayer來播放影片NSString *filePath = [[NSBundle mainBundle] pathForResource:@"backspace" ofType:@"mov"];NSURL *sourceMovieURL = [NSURL fileURLWithPath:filePath];moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:sourceMovieURL];moviePlayer.view.frame=CGRectMake(0, 0, 1024, 768);moviePlayer.controlStyle=MPMovieControlStyleNone;// Play the movie![self.view addSubview:moviePlayer.view]; 使用AVPlayer來播放影片NSString *filePath = [[NSBundle mainBundle] pathForResource:@"backspace" ofType:@"mov"];NSURL *sourceMovieURL = [NSURL fileURLWithPath:filePath];AVAsset *movieAsset = [AVURLAsset URLAssetWithURL:sourceMovieURL options:nil];AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:movieAsset];AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];playerLayer.frame = self.view.layer.bounds;playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;[self.view.layer addSublayer:playerLayer];[player play];

?基本寫法有了 但是 至少我們還需要 play ?stop ?speed retreat 等方法. ?寫完 發現 有個 大bug ?: 反復 進出視頻的頁面 會崩潰. 方法 當然是標配 那是什么問題呢? ?

其實理解起來很簡單, 反復進入,并且 視頻流加載 肯定 不如 普通文本快, 那么反復進入加載 很容易出現 調用空指針 然后掛掉. 所以

第一步 ? ?處理流媒體崩潰問題 這塊不能用簡單的同步機制 要異步操作.

第二步 ? ?并且 重要的是 使用完 或者 提前退出 要把對應的通知 取消結束掉 ?這也是問題之一 ?.

以下作為參考方法:?

需要添加 頭文件 ??#import <AVFoundation/AVFoundation.h>

轉載于:https://www.cnblogs.com/someonelikeyou/p/4861479.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/274818.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274818.shtml
英文地址,請注明出處:http://en.pswp.cn/news/274818.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

figma下載_遷移至Figma

figma下載Being an intuitive and user-friendly tool and having the possibility of real-time collaboration are some of the main reasons people choose to use Figma. But the migration process to Figma may sometimes be painful or time-consuming. 人們選擇使用Fig…

metaWeblog 相關的參數

Function: Creates a new post on your blog. tags如果沒會自動那一個 但是categroies如果與已經建立的不同,就會忽略掉的 可以用 string.replace(\n,).split(,) Parameters: Blog ID – For use in multisite installations, typically 0 for single sites Username – WordPr…

TypeScript 常用的新玩法

大家好&#xff0c;我是若川。持續組織了6個月源碼共讀活動&#xff0c;感興趣的可以點此加我微信 ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列上周分…

《Programming in Lua 3》讀書筆記(十二)

日期&#xff1a;2014.7.14 PartⅡ Object-Oriented ProgrammingLua中實現面向對象編程。“如同OOP對象&#xff0c;table擁有狀態&#xff1b;如同OOP對象&#xff0c;table擁有標識符---self&#xff0c;用來與其他變量做區分&#xff0c;而且兩個table擁有同樣的值也是…

(轉)AS3中的stage,this,root的區別

要了解這個問題就要先對flash中的顯示對象結構有一個大概的了解&#xff1a; 第一級&#xff1a;舞臺&#xff1b; 第二級&#xff1a;當前SWF&#xff1b; 第三級&#xff1a;各種容器及可視對象&#xff08;如&#xff1a;文本框&#xff0c;位圖……&#xff09;&#xff1b…

面試官是怎樣高效面試的(面試官的“套路”

大家好&#xff0c;我是若川。持續組織了6個月源碼共讀活動&#xff0c;感興趣的可以點此加我微信 ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列最近正…

微服務負載均衡實現高可用_使用負載平衡實現大容量可用性

微服務負載均衡實現高可用Written by Yona Gidalevitz由Yona Gidalevitz撰寫 Most users of the web are blissfully unaware of the sheer scale of the process responsible for bringing content across the Internet. There are literally miles of Internet between you …

Visual Studio 2008自帶的Windows 系統使用的各種圖標、光標和動畫文件

1&#xff0c;Visual Studio 2008自帶的1000多個 Windows 系統使用的各種圖標、光標和動畫文件 在Visual Studio 2008的安裝目錄下&#xff0c; /Microsoft Visual Studio 9.0/Common7/VS2008ImageLibrary/2052文件夾下面&#xff0c;有一個VS2008ImageLibrary.zip&#xff0c;…

Android中導入第三方jar

右鍵工程&#xff0c;Build path,Java build path,選擇libraries在右邊的按鈕中點擊“Add Library”選擇“User library”,點擊“下一步”點擊“User librarys”按鈕在出現的界面中點擊“New..”按鈕在彈出的界面中隨便起一個名字&#xff0c;點擊“確定”點擊“Add jars”按鈕…

19歲中專學歷是怎么在廣州找到前端工作的?

大家好&#xff0c;我是若川。持續組織了8個月源碼共讀活動&#xff0c;感興趣的可以點此加我微信 ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列本文來…

tcp 接收端優雅的寫法_如何更優雅地接收設計反饋

tcp 接收端優雅的寫法重點 (Top highlight)It’s rare to meet a designer that doesn’t take pride in their work. After all, we are creatives and it’s what we love to do. Although design is teachable, there is a bit of natural skill and talent that comes into…

C++頭文件一覽表

傳統 C   #include <assert.h>    //設定插入點   #include <ctype.h>//字符處理   #include <errno.h>//定義錯誤碼   #include <float.h>//浮點數處理   #include <fstream.h>//文件輸入&#xff0f;輸出   #include &l…

一份 2.5k star 的《React 開發思想綱領》

大家好&#xff0c;我是若川。持續組織了6個月源碼共讀活動&#xff0c;感興趣的可以點此加我微信 ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列翻譯自…

asp.net生成jason給js

[WebMethod(EnableSession true)][ScriptMethod]public static object TEST(string testval){int type 0;string message "";int precent 0;return new { type type, message message, precent precent };} 轉載于:https://www.cnblogs.com/bulege/archive/20…

文案寫作軟件_11種可改善網站用戶體驗的文案寫作技術

文案寫作軟件Written by John Stevens約翰史蒂文斯 ( John Stevens)撰寫 When we talk about user experience and your website, it is easy to get caught up in the site’s design and navigation options. While that is important, the words you place on the page are…

Table.Rows.Remove(dr)和Table.Delete()的區別

一個DataRow對象剛被創建之后其狀態是Detached&#xff0c;是孤立的一個存在&#xff0c;所以建立了DataRow之后在DataRow中的單元填充了數據后還要通過DataTable.Rows.Add(DataRow)方法將此DataRow添加到DataTable&#xff0c;DataRow添加到DataTable后, 這個DataRow的狀態就…

張小龍談用戶體驗

原文&#xff1a;http://sd.csdn.net/a/20120510/2805483.html從Foxmail到騰訊“七星級產品”QQ郵箱&#xff0c;再到騰訊核武器級產品微信。在外界看來&#xff0c;騰訊副總裁、廣州研發部總經理張小龍作風低調&#xff0c;很少接受正式的媒體采訪。然而作為當今國內最優秀的產…

如何高效學習前端新知識,我推薦這些~

眾所周知&#xff0c;關注公眾號可以了解學習掌握技術方向&#xff0c;學習優質好文&#xff0c;落實到自己項目中。還可以結交圈內好友&#xff0c;讓自己融入到積極上進的技術氛圍&#xff0c;促進自己的技術提升。話不多說&#xff0c;推薦這些優質前端公眾號前端之神100w閱…

web開發集成數字證書_每個數字設計師都應該知道的Web開發的七個原則

web開發集成數字證書A career path into digital design is often winding, meaning many practitioners come from adjacent fields as diverse as graphic design, web development, research, or even anthropology. As a result, two people working in a similar role may…

【轉】CentOS 6.6 升級GCC G++ (當前最新版本為v6.1.0) (完整)

原文地址&#xff1a;https://www.cnblogs.com/lzpong/p/5755678.html 我這里是centos7 升級到gcc8.1&#xff0c;過程差不多&#xff0c;參考這篇文章&#xff0c;記錄一下。 ---原文--- CentOS 6.6 升級GCC G (當前最新GCC/G版本為v6.1.0) 沒有便捷方式, yum update.... yu…