AVPlayer周りの設計tips

E2c86baa99178b8400a2ef49ef861a6c?s=47 toshi0383
October 09, 2018

 AVPlayer周りの設計tips

potatotips #55 の発表資料です。

E2c86baa99178b8400a2ef49ef861a6c?s=128

toshi0383

October 09, 2018
Tweet

Transcript

  1. AVPlayerपΓͷઃܭtips potatotips #55 Oct 9, 2018 Toshihiro Suzuki © Toshihiro

    Suzuki 2018 1
  2. whoami @toshi0383 (Toshihiro Suzuki) ಡΈํ: τογʔ or... © Toshihiro Suzuki

    2018 2
  3. ʮ౦ژ౎࠷଎ͷஉʯ͞Μ © Toshihiro Suzuki 2018 3

  4. झຯ: ѪंͰυϥΠϒ (ՈͰ) © Toshihiro Suzuki 2018 4

  5. job AbemaTV iOS/tvOS ετΫϥ (Streaming Client Team) ಈը࠶ੜ඼࣭ © Toshihiro

    Suzuki 2018 5
  6. Developer Blog https://developers.cyberagent.co.jp/blog/archives/17579/ © Toshihiro Suzuki 2018 6

  7. ࠓ೔ͷςʔϚ © Toshihiro Suzuki 2018 7

  8. AVPlayerपΓͷίʔυΛͲ ͏੔ཧͨ͠Β͍͍͔ ͋͘·ͰҰྫͳͷͰɺ͝ࢀߟఔ౓ʹɻ © Toshihiro Suzuki 2018 8

  9. ྲྀΕ —લఏͱͳΔํ਑ —ઃܭͷશମ૾Λ၆ᛌ © Toshihiro Suzuki 2018 9

  10. ํ਑ —AVPlayer͸UIͱͯ͠ଊ͑ͳ͍ —replaceCurrentItem͸࢖Θͳ͍ (লུ) © Toshihiro Suzuki 2018 10

  11. ҰൠతʹΑ͘ݟΔίʔυ class ViewController: UIViewController { var player: AVPlayer? ... override

    func viewDidLoad() { super.viewDidLoad() player?.play() } } © Toshihiro Suzuki 2018 11
  12. Α͘ݟΔίʔυͷ໰୊఺ —playerΛ৮Δίʔυ͕ࢄΒ͹͍ͬͯͯݟ௨͕͠Α͘ͳ ͍ —ଞͷView͔Β৮Γ͍ͨ৔߹ʹڑ཭͕͋Δ © Toshihiro Suzuki 2018 12

  13. ͦ΋ͦ΋ϓϨΠϠʔ͔ͩΒͬͯView ʹറΒΕ͍ͯΔͷ͕ѱ͍ͷͰ͸ © Toshihiro Suzuki 2018 13

  14. AVPlayerͷॳظԽ΍ૢ࡞͸ϝΠϯε Ϩουඞਢͱ͍͏ݴ͍఻͑ ࠷ۙ͸͋·Γฉ͔ͳ͍͚ͲɺҎલ͸ͦ͏͍͏ৗ͕ࣝଘࡏ ͨ͠ؾ͕͢Δɻ © Toshihiro Suzuki 2018 14

  15. ໎৴Ͱ͢ ؾͷ͍ͤͳͷͰ๨Ε·͠ΐ͏ © Toshihiro Suzuki 2018 15

  16. ͨͩ͠ KVOͷొ࿥͸ϝΠϯεϨουͷํ͕͍͍ͱ͍͏هड़͋Γ https://developer.apple.com/documentation/avfoundation/avplayer © Toshihiro Suzuki 2018 16

  17. ͋ͱ ͜͏͍͏࿩΋͋ΔͷͰཁݕূ https://speakerdeck.com/kyoheig3/abema-devcon?slide=24 © Toshihiro Suzuki 2018 17

  18. ͱ͸͍͑ɺ ϝΠϯεϨου == UI ʹറΒΕΔඞ ཁ͸ͳ͍͸ͣ Appleͷαϯϓϧ΋ AssetPlaybackManager ͕playerΛ؅ཧ͍ͯ͠Δ ΋ͬͱ্ྲྀͰ΍ͬͯ͠·͓͏ʂ

    © Toshihiro Suzuki 2018 18
  19. ၆ᛌΠϥετ © Toshihiro Suzuki 2018 19

  20. RxSwift // ViewModel let control = VideoPlayerControl() ... requestReload .startWith(())

    // NOTE: initial load .subscribe(onNext: { [weak self] in guard let me = self else { return } me.manager = VideoPlayerManager(url: me.url, control: me.control) me.manager.player.asObservable() .bind(to: me.playerRelay) .disposed(by: me.manager.playerDisposeBag) }) .disposed(by: disposeBag) © Toshihiro Suzuki 2018 20
  21. RxSwift // ViewController viewModel.playerRelay.asObservable() .observeOn(ConcurrentMainScheduler.instance) .subscribe(onNext: { [weak self] player

    in self?.playerView.playerLayer.player = player }) .disposed(by: disposeBag) © Toshihiro Suzuki 2018 21
  22. ·ͱΊ —AVPlayerੜ੒ΛUI૚͔Β෼཭ͨ͠Βগ͠εοͱͨ͠ —ManagerΫϥεʹ੾Γग़ͤͨ͜ͱͰɺը໘Λލ͍Ͱ ૢ࡞&ੜଘ͕Մೳ => Picture-in-Pictureͱ͔ෳ਺ϓϨΠϠʔͱ͔ —VideoPlayerStream Λ࢖͏͜ͱͰɺϓϨΠϠʔͷ ڍಈΛmockՄೳ. (testable!)

    © Toshihiro Suzuki 2018 22
  23. toshi0383/VideoPlayerManager ৭ʑ్தͰ্͕͕ͬͯ͢·͢ɻ https://github.com/toshi0383/VideoPlayerManager Open-Source! © Toshihiro Suzuki 2018 23

  24. ͪͳΈʹ ࣮͸AbemaTV iOSΞϓϦ΋͜Ε͔Β͜ͷํ਑ͰϦϑΝ ΫλʹऔΓֻ͔Δͱ͜Ζɻ tvOSͱڞ௨Ͱ࢖͑ΔϥΠϒϥϦʹ͍ͨ͠ɻ ·ͩ·ͩࡉ͔͍ͱ͜Ζ͸͜Ε͔Βߟ͑ΔͷͰɺ͝ҙݟื ूதͰ͢ɻ © Toshihiro Suzuki

    2018 24
  25. ͪͳΈʹͪͳΈʹ Ұॹʹಇ͘஥ؒ͸·ͩ·ͩืूதͰ͢ ҰॹʹςετۦಈͰࢹௌମݧ޲্ ͠·͠ΐ͏ ! © Toshihiro Suzuki 2018 25

  26. ͓ΘΓ © Toshihiro Suzuki 2018 26

  27. ࢀߟࢿྉ —Apple AVPlayerυΩϡϝϯτ —AVPlayerϕετϓϥΫςΟε by @KyoheiG3 —ಈըΞϓϦΛͳΊΒ͔ʹಈ͔ٕ͢ज़ by @dekatotoro ©

    Toshihiro Suzuki 2018 27
  28. Toshihiro Suzuki ! Twitter/GitHub/GTSport => @toshi0383 Email: t.suzuki326@gmail.com © Toshihiro

    Suzuki 2018 28