iOS 關於流媒體 的初級認識與使用

來源:互聯網
上載者:User

標籤:style   blog   class   code   c   java   

1.流媒體指在Internet/Intranet中使用串流技術的連續時基媒體,如:音頻、視頻或多媒體檔案。流式媒體在播放前並不下載整個檔案,只將開始部分內容存入記憶體,流式媒體的資料流隨時傳送隨時播放,只是在開始時有一些延遲。流媒體實現的關鍵技術就是串流。

2.這裡的流媒體地址是指服務端那邊已經調好格式的可以在ios上播放的視頻流。

 舉例:http://www.jxvdy.com/file/upload/201309/18/18-10-03-19-3.mp4

3.iOS的影片播放 MediaPlayer 和 AVPlayer(framework)

在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];

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.