2015-12-02 89 views
0

我有一個Swift應用程序。我想通過使用moviePlayer播放一些視頻。我正在使用下面的代碼。視頻拉伸問題iOS Swift

let url = NSURL.fileURLWithPath(path) 
     moviePlayer = MPMoviePlayerController(contentURL: url) 
//  moviePlayer?.controlStyle = .None 
     if let player = moviePlayer { 
      player.view.frame = CGRect(x: 20, y: 165, width: widthVideoView, height: heightVideoView) 
      player.prepareToPlay() 
      player.scalingMode = .AspectFill 
      self.view.addSubview(player.view) 

     } 

播放視頻沒問題。但現在我的視頻被拉長了。我認爲這是因爲

 player.scalingMode = .AspectFill 

我的截圖是這樣的。 enter image description here

所以我改變

player.scalingMode = .AspectFit 

然後我的屏幕就像這樣(用黑色屏幕頂部底部。)我如何處理這個問題。 enter image description here

+0

您試圖實現的是什麼? – Armin

+0

看看我的第一個截圖視頻拉伸了嗎?在我的第二個地方有黑色的空間。我希望像第一個一樣全尺寸的視頻,而不是拉伸。 – Amsheer

+0

試試這個player.view.frame = CGRect(x:0,y:0,width:widthVideoView,height:heightVideoView)和layer.scalingMode = .AspectFit –

回答

0

很抱歉的編輯答案,如果你讀了實況:https://developer.apple.com/library/prerelease/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/index.html#//apple_ref/c/tdef/MPMovieScalingMode

  • .aspectFit:將創建blackBar,因爲它使視頻
  • .aspectFill的縱橫比,會像一個放大(沒有黑條,但視頻被剪切)
    • 。填充將拉伸視頻以適應(我認爲您需要這一個或更改視圖以遵循寬高比)。

如果你不尊重原始寬高比:它總是伸展或有黑網吧太補。 因此,您可以將scalingMode更改爲。填充或更改視圖以尊重寬高比

+0

我不明白你的意思? – Amsheer

+0

有關寬高比和當前視頻標準的更多信息:https://en.wikipedia.org/wiki/Aspect_ratio_(image)#Current_video_standards – kholl

+0

我沒有測試過,但這一個似乎很有希望獲得視頻https ://discussions.apple.com/thread/2794706開始= 0&TSTART = 0 – kholl