AVKit

2024. 10. 21. 19:34·iOS/Framework
반응형

AVKit이란?

 

이전 포스팅에서 AVFoundation은 여러 미디어 데이터를 다루는데 중점을 둔 프레임워크라고 배웠다.

그렇다면 그 데이터를 실제 재생하고 컨트롤하는 UI는 어디에 있을까 ??

 

위에 그림을 보면 AVFoundation은 UIKit보다 아래에 있어 표준 UI를 제공해주지 않는다.

그러므로 미디어 데이터를 다루는 UI를 만들기 위해서는 AVFoundation보다 아래 계층에 있어야한다. 

하지만 이 경우는 상당히 low-level까지의 지식과 많은 작업량이 필요한데 이 때 애플에서는 AVkit이라는 걸 제공하게된다.

 

 

역할

Create user interfaces for media playback, complete with transport controls, chapter navigation, picture-in-picture support, and display of subtitles and closed captions.

 

  • AVFoundation위에 구축된 보조 프레임워크로 플랫폼의 기본 재생 환경과 일치하는 앱용 플레이어 인터페이스를 쉽게 제공한다.
  • 재생 중인 컨텐츠와 가장 잘 일치하는 플레이어 인터페이스를 제공하며 자막과 CC((Closed\; Captions))이 자동으로 표현
  • 탐색 가능한 챕터 마커 제공
  • 대체 미디어 옵션을 선택하는 컨트롤 제공

정리하면 커스텀 없이 기본 재생 UI를 원할 때 사용한다.

 

사용

import UIKit
import SwiftUI
import AVKit

class ViewController: UIViewController {
    
    private let button: UIButton = {
        var config = UIButton.Configuration.plain()
        config.title = "Play"
        
        return UIButton(configuration: config)
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        view.addSubview(button)
        
        button.translatesAutoresizingMaskIntoConstraints = false
        
        button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        button.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        
        let action = UIAction(title: "Play", handler: { _ in self.playVideo() })
        button.addAction(action , for: .primaryActionTriggered)
    }
    
    private func playVideo() {
        let fileURL: URL = Bundle.main.url(forResource: "test", withExtension: ".mov")!
        
        let playerController = AVPlayerViewController()
        let player = AVPlayer(url: fileURL)
        
        playerController.player = player
        
        self.present(playerController, animated: true) {
            player.play()
        }
    }
    
 
}

 

결과

 

기본 player ui와 함께 다양한 기본 컨트롤러가 구현되어있는 것을 볼 수 있다.

 

 


참고

 

AVKit | Apple Developer Documentation

Create user interfaces for media playback, complete with transport controls, chapter navigation, picture-in-picture support, and display of subtitles and closed captions.

developer.apple.com

 

 

AVPlayerViewController | Apple Developer Documentation

A view controller that displays content from a player and presents a native user interface to control playback.

developer.apple.com

 

반응형

'iOS > Framework' 카테고리의 다른 글

소셜 로그인 구현하기  (1) 2025.01.03
AVFoundation (4) [AVAudioSession]  (3) 2024.10.22
AVFoundation (3) [AVPlayerLayer]  (1) 2024.10.22
AVFoundation (2) [AVPlayer, AVPlayerItem]  (0) 2024.10.21
AVFoundation (1) [AVAsset]  (2) 2024.10.21
'iOS/Framework' 카테고리의 다른 글
  • AVFoundation (4) [AVAudioSession]
  • AVFoundation (3) [AVPlayerLayer]
  • AVFoundation (2) [AVPlayer, AVPlayerItem]
  • AVFoundation (1) [AVAsset]
Hamp
Hamp
남들에게 보여주기 부끄러운 잡다한 글을 적어 나가는 자칭 기술 블로그입니다.
  • Hamp
    Hamp의 분리수거함
    Hamp
  • 전체
    오늘
    어제
    • 분류 전체보기 (304)
      • CS (30)
        • 객체지향 (2)
        • Network (7)
        • OS (6)
        • 자료구조 (1)
        • LiveStreaming (3)
        • 이미지 (1)
        • 잡다한 질문 정리 (0)
        • Hardware (2)
        • 이론 (6)
        • 컴퓨터 그래픽스 (0)
      • Firebase (3)
      • Programing Langauge (37)
        • swift (32)
        • python (4)
        • Kotlin (1)
      • iOS (132)
        • UIKit (37)
        • Combine (1)
        • SwiftUI (32)
        • Framework (7)
        • Swift Concurrency (22)
        • Tuist (6)
        • Setting (11)
        • Modularization (1)
        • Instruments (6)
      • PS (59)
        • 프로그래머스 (24)
        • 백준 (13)
        • LeetCode (19)
        • 알고리즘 (3)
      • Git (18)
        • 명령어 (4)
        • 이론 (2)
        • hooks (1)
        • config (2)
        • action (7)
      • Shell Script (2)
      • Linux (6)
        • 명령어 (5)
      • Spring (13)
        • 어노테이션 (1)
        • 튜토리얼 (11)
      • CI-CD (4)
      • Android (0)
        • Jetpack Compose (0)
      • AI (0)
        • 이론 (0)
  • 블로그 메뉴

    • 홈
    • 태그
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    SwiftUI
    GIT
    CS
    Swift
    dfs
    protocol
    IOS
    lifecycle
    boostcamp
    Tuist
    concurrency
    AVFoundation
    프로그래머스
    UIKit
    dp
    dispatch
    투포인터
    Spring
    백준
    property
  • 최근 댓글

  • 최근 글

  • 반응형
  • hELLO· Designed By정상우.v4.10.0
Hamp
AVKit
상단으로

티스토리툴바