Pro Yearly is on sale from $80 to $50! »

複数のライブ映像を同期再生するのが大変だったので知見をお伝えします

3bf6da1f63cd8b7a2f802f95c269ed80?s=47 FromAtom
August 31, 2018

 複数のライブ映像を同期再生するのが大変だったので知見をお伝えします

iOSDC Japan 2018
2018/08/31 10:50~
Track C

3bf6da1f63cd8b7a2f802f95c269ed80?s=128

FromAtom

August 31, 2018
Tweet

Transcript

  1. ෳ਺ͷϥΠϒө૾Λ ಉظ࠶ੜ͢Δͷ͕େมͩͬͨͷͰ ஌ݟΛ͓఻͑͠·͢ iOSDC Japan 2018 2018.8.31 10:50~ Track C

    pixiv.inc FromAtom
  2. • FromAtom / @FromAtom / id:FromAtom • ͸ͯͳΠϯλʔϯˠ͸ͯͳΞϧόΠτˠϐΫγϒ • pixiv

    Sketch / pixiv Sketch LIVE / pixivίϛοΫ • Swift 1.2 ͔ΒiOSΞϓϦ։ൃͷੈք΁   ࣗݾ঺հ
  3. ͓ֆ͔͖ίϛϡχέʔγϣϯΞϓϦ pixiv Sketch  

  4.   એ఻

  5.   ϐΫγϒגࣜձࣾͬͯձࣾͰ͢

  6.   ͍Ζ͍Ζ΍ͬͯ·͢

  7.   ͜͜Ͱ౾஌ࣝ

  8.   pixivͷ "p" ͸খจࣈ

  9.   γϧόʔεϙϯαʔͰ͢ʂ

  10.   ϊϕϧςΟ΋༻ҙ͓ͯ͠Γ·͢ʂ

  11.  

  12.  

  13.   खʹೖΕΔํ๏

  14.   ϐΫγϒࣾһΛݟ͚͍ͭͯͩ͘͞

  15.  

  16.   ʮίʔυϨϏϡʔ͓ئ͍͠·͢ʯ

  17.   ࠓ೔͸ઌண15ਓʹϓϨθϯτʂ ࣋ͬͯΔࣾһΛ୳ͤʂ

  18. ෳ਺ͷϥΠϒө૾Λ ಉظ࠶ੜ͢Δͷ͕େมͩͬͨͷͰ ஌ݟΛ͓఻͑͠·͢   iOSDC Japan 2018 08/31 10:50

    Track C  pixiv.inc FromAtom
  19.   iOSͰಈը࠶ੜ͢Δ

  20.   iOSͰಈը࠶ੜ͢Δ ࢀߟɿ [iOS] iOSͰಈըΛ࠶ੜ͢Δ̐ͭͷํ๏ | Developers.IO (https://dev.classmethod.jp/smartphone/ios-video/) ࠶ੜํ๏

    ൑அج४ ࣮૷ίετ MPMoviePlayerController iOS9 ͔Β Deprecated - WKWebView ؆୯ʹαοͱग़͍ͨ࣌͠ খ AVPlayerViewController WKWebViewΑΓগ͚ͩ͠ڽΓ͍ͨ࣌ খ AVPlayer ෳࡶͳ੍ޚɾදࣔΛߦ͍͍ͨ࣌ େ
  21.   WKWebView or AVPlayerViewController Λ࢖͓͏ʂʂʂ

  22.   AVPlayer͸େม͔ͩΒ ࢖Θͳ͍Α͏ʹؤுͬͯʂʂʂ

  23.   AVPlayerΛ͔ͭ͏࣌

  24.   AVPlayerΛ͔ͭ͏࣌ • ෳࡶͳ࠶ੜ੍ޚΛߦ͍͍ͨ • ಠࣗͷૢ࡞ύωϧΛ࡞Γ͍ͨ • ϑϧεΫϦʔϯػೳΛࣗ࡞͍ͨ͠ •

    ෳ਺ಈըͷಉظ࠶ੜΛ࣮ݱ͍ͨ͠
  25.   AVPlayerΛ͔ͭ͏࣌ • ෳࡶͳ࠶ੜ੍ޚΛߦ͍͍ͨ • ಠࣗͷૢ࡞ύωϧΛ࡞Γ͍ͨ • ϑϧεΫϦʔϯػೳΛࣗ࡞͍ͨ͠ •

    ෳ਺ಈըͷಉظ࠶ੜΛ࣮ݱ͍ͨ͠
  26.   ͳΜͰෳ਺ಈըͷಉظ͢ΔΜʁ

  27.   pixiv Sketch LIVE

  28. ෳ਺ਓ഑৴   • ࠷େ4ਓ·Ͱಉ࣌഑৴͕Ͱ͖Δ • ഑৴ऀ͸్தͰ૿ݮ͢Δ • ࢹௌऀ͸͢΂ͯͷಈըΛ࠶ੜ

  29. ෳ਺ਓ഑৴   • ࠷େ4ਓ·Ͱಉ࣌഑৴͕Ͱ͖Δ • ഑৴ऀ͸్தͰ૿ݮ͢Δ • ࢹௌऀ͸͢΂ͯͷಈըΛ࠶ੜ 1

    2 3 4
  30.   ෳ਺ਓ഑৴ • ഑৴ऀಉ࢜͸WebRTCͰ௿஗ԆʹίϛϡχέʔγϣϯՄೳ • ࢹௌऀଆʹ͸HLSಈը͕࠷େ4ͭ߱ͬͯ͘Δ • ී௨ʹ࠶ੜ͢ΔͱHLSಈըͷ࠶ੜλΠϛϯά͕ζϨΔ •

    ձ࿩ͷ಺༰͕ζϨͯ·ͱ΋ʹࢹௌͰ͖ͳ͍
  31.   ෳ਺HLSʢಈըʣͷಉظ࠶ੜ͕ඞཁ

  32.   ͜ͷൃදͷํ਑ • ϥΠϒ഑৴͞Ε͍ͯΔHLSಈըͷ࿩Λ͠·͢ • ࣮૷ํ๏͸ WWDC 2017ͷ "Advances

    in HTTP Live Streaming" Ͱ΄΅෼͔Δ • αϯϓϧίʔυ΋͋Γ·͢ • ͳͷͰৄ͍࣮͠૷ͷ࿩͸ͤͣɺίπ΍ϊ΢ϋ΢Λڞ༗͠·͢ • কདྷෳ਺HLSΛಉظ࠶ੜ͢Δ࣌ͷखॿ͚ʹͳΔࢿྉΛ໨ࢦ͢ ࢀߟɿ Advances in HTTP Live Streaming - WWDC2017 (https://developer.apple.com/videos/play/wwdc2017/504/)
  33.   1ͭͷHLSಈըΛ࠶ੜ͢Δࡍͷίπ

  34.   AVPlayerLayerͷίπ LICENSE: "Big Buck Bunny" by Blender Foundation

    is licensed under CC BY 3.0 ૝ఆ ݱ࣮
  35.   • .frame Λઃఆ͠ͳ͍ͱಈըαΠζ͕͓͔͘͠ͳΔ AVPlayerLayerͷίπ

  36.   KVOͷίπ • ͜ͷ5छྨΛ؂ࢹ͓ͯ͘͠ • .status, .loadedTimeRangesɿओʹಉظ࠶ੜʹ࢖͏ • .isPlayback*ɿϩʔσΟϯάɾϦϩʔυදࣔͷϋϯυϦϯάʹ࢖͏

  37.   KVOͷίπ • removeObserver ͤͣʹഁغ͢Δͱ࣮ߦ࣌Ϋϥογϡ • iOS9 ͔Β NotificationCenter

    ͷ removeObserver ͸ෆཁʹͳ͚ͬͨͲKVO͸ผ ࢀߟɿiOS9Ҏ߱Ͱ͸ "NotificationCenter.default.removeObserver(_:name:object:)" Λdeinitʹॻ͔ͳͯ͘΋ྑ͍Ͱ͢Αɻ(https://fromatom.hatenablog.com/entry/2017/12/13/135542)
  38.   KVOͷίπ • addObserver ͍ͯ͠ͳ͍ঢ়ଶͰ removeObserver ͢Δͱ࣮ߦ࣌Ϋϥογϡ • addObserver

    ͞Ε͍ͯΔ͔஌Δํ๏͕ͳͦ͞͏ • DispatchQueueͱϑϥάΛ༻͍ͯஸೡʹ؅ཧ͢Δඞཁ͕͋Δ
  39.   block-based KVOΛ࢖͏ • removeObserver ͠ͳͯ͘΋Ϋϥογϡ͠ͳ͍ • observer?.invalidate() Ͱ໌ࣔతʹഁغ΋Ͱ͖Δ

  40.   ෳ਺ͷHLSಈըΛ࠶ੜ͢Δࡍͷίπ

  41.   iOS 9 ͷαϙʔτΛ੾Δ • ಉظ࠶ੜʹඞཁͳAPI͕ iOS 10+ •

    iOS 9 ҎલͰ͸Ͳ͏͕Μ͹ͬͯ΋ແཧ • શͯͷಈըΛಉ࣌ʹϦϩʔυͯٙ͠ࣅಉظͳͲ͸ՄೳʢζϨΔʣ • ΋͘͠͸ iOS 9 ͷ৔߹͚ͩಈըΛݟΕͳ͘͢Δ
  42.   ಉظͷ࢓૊Έ ͬ͘͟Γͱ

  43.   1 2 3 4

  44.   ਌ ࢠ ࢠ ࢠ Seekͯ͠࠶ੜ

  45.   ਌ ࢠ ࢠ ࢠ ζϨΛΈΔ

  46.   ਌ ࢠ ࢠ ࢠ Seekͯ͠࠶ੜ

  47.   ઃܭͷίπ • View (VC) ʹσʔλ͕ີ݁߹͠΍͍͢ • ෳ਺ͷಈը (UIView)

    ͕ີ݁߹ͯ͠େมʹͳΔʢͳͬͨʣ • ManagerΛ࡞ΓಉظʹඞཁͳσʔλΛView֎ʹग़͢ • γϯάϧτϯ or ಈըΛ؅ཧ͢ΔView (VC) ʹΠϯελϯεΛ΋ͨͤΔ
  48.   ࢠ ਌

  49.   ࢠ ਌ ͍·࣌ؒͲΜͳʁ

  50.   ࢠ ਌ ͍·࣌ؒͲΜͳʁ σʔλ

  51.   ࢠ Manager σ ʔ λ ਌

  52.   ࢠ Manager σ ʔ λ ਌ ͍·࣌ؒͲΜͳʁ

  53.   ࢠ Manager σ ʔ λ ࢠ ࢠ ਌

  54. খٳࢭ ͜͜Ͱ࢒Γ5෼ or 10෼ܦա ͩͱ͍͍ײ͡Β͍͠Α  

  55.   ϋϚͬͨ໰୊

  56.   ਌ಈը͕ૣૹΓ͞ΕΔ • ࠶ੜˠ͠͹Β͘ࢹௌˠఀࢭˠ࠶ੜ Λߦͳ͏ͱى͜Δ • Buffer͕͔ͬ͠Γͱཷ·͍ͬͯΔͱൃੜ • ૣૹΓ͕ऴΘΔ·Ͱಉظ͕Ͱ͖ͳ͍ͷͰࢠͷಈը΋ࢭ·Δ

  57.   ਌ಈը͕ૣૹΓ͞ΕΔ • preferredForwardBufferDuration ͷ஋Λখͯ͘͞͠ղܾ • ੜ੒͞Ε͍ͯΔHLSͷઃఆͰม͑ͨ΄͏͕ແ೉ • σϑΥϧτ͸"0"ͰࣗಈͰ͍͍ײ͡ʹͯ͘͠ΕΔ

    • automaticallyWaitsToMinimizeStalling Λ true ʹ͠ͳ͍ͱ༗ޮʹͳΒͳ͍
  58.   ࢠͷಈը͕࠶ੜ͞Εͳ͍ • ಉظ࠶ੜʹ͸HLSͷ EXT-X-PROGRAM-DATE-TIME λάΛ࢖͏ • ͜ͷλάͰࢦఆ͞Ε͕ͨ࣌ؒͣΕ͍ͯͨ •

    ͲͷϨΠϠʔͷ໰୊͔Θ͔ΒͣɺݪҼڀ໌ʹ͕͔͔࣌ؒͬͨ • αʔόαΠυͱͷίϛϡχέʔγϣϯ͕େࣄ ࢀߟɿHLS WWDC 2017 Preliminary spec (https://developer.apple.com/streaming/HLS-WWDC-2017-Preliminary-Spec.pdf)
  59.   σόοάํ๏

  60.   HLS͕ు͘ΤϥʔΛݟΔํ๏ • .AVPlayerItemNewErrorLogEntry ͷ௨஌Λड͚औΔ • ௨஌Λड͚औͬͨΒ AVPlayer ͕͍࣋ͬͯΔ

    errorLog() ͷ࠷ޙΛݟΔ
  61.   AVPlayerItemErrorLogEvent.errorComment ͷத਎ Failure Error Code Authentication failures 401

    Unauthorized Client doesn’t have permissions 403 Forbidden Resource unavailable but may become available in the future 404 Not Found Resource unavailable and will never become available in the future 410 Gone Internal server errors 500 Internal Server Error Invalid response from gateway 502 Bad Gateway Server unavailable 503 Service Unavailable Gateway timeouts 504 Gateway Time-Out ࢀߟɿError Handling Best Practices for HTTP Live Streaming - WWDC 2017 (https://developer.apple.com/videos/play/wwdc2017/514/?time=218)
  62.   αʔόαΠυͱͷ࿈ܞ • αʔόαΠυ͸֤ϓϥοτϑΥʔϜʹରԠ͢Δඞཁ͕͋Δ • iOSͷSafariͰಈ͍ͯ΋AVPlayerͰ͸ಈ͔ͳ͍͜ͱ͕͋Δ • खݩͰؾܰʹσόοάͯ͠΋Β͑Δ΄͏͕Α͍

  63.   σόοά༻ΞϓϦ • HLSͷURL͔Β࠶ੜͰ͖Δ • ֤छϩάΛਨΕྲྀ͍ͯ͠Δ • In-HouseϏϧυͰ഑෍ LICENSE:

    "Big Buck Bunny" by Blender Foundation is licensed under CC BY 3.0
  64.   Androidͷ৔߹͸ʁ

  65.   google/ExoPlayer Λ࢖͑͹ղܾ • Googleۘ੡ • શ෦΍ͬͯ͘ΕΔʂ࠷ߴʂ • https://github.com/google/ExoPlayer

  66.   ·ͱΊ