Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flutterで動画を再生するためには

 Flutterで動画を再生するためには

3187acdb47cb44678ad716c3228bf91b?s=128

Kentaro Kawakami

May 27, 2021
Tweet

Transcript

  1. FlutterͰಈըΛ࠶ੜ͢ΔͨΊ ʹ͸ ઒্ ݈ଠ࿠

  2. About Me ઒্ ݈ଠ࿠ FRESH LIVEɺCLͰiOSΞϓϦͷ։ൃ ΛܦͯFlutterͰ։ൃதɻFlutterྺ͸ 6ϲ݄͘Β͍ ,FFFFFO ,OTDIXBS[F

    Cyberagent, Inc.
  3. ໨࣍ • ύοέʔδͷ঺հ • video_playerʹ͍ͭͯ • ࣮૷Λ௥ͬͯΈΔ • ػೳΛ௥Ճ͢Δ •

    ·ͱΊ
  4. ໨࣍ • ύοέʔδͷ঺հ • video_playerʹ͍ͭͯ • ࣮૷Λ௥ͬͯΈΔ • ػೳΛ௥Ճ͢Δ •

    ·ͱΊ
  5. ύοέʔδͷ঺հ • video_player • pub.dev • GitHub • fl utter͕ग़͍ͯ͠Δ

    • iOS/Android/WebʹରԠ • iOS͸Objective-CɺAndroid͸Java
  6. ໨࣍ • ύοέʔδͷ঺հ • video_playerʹ͍ͭͯ • ࣮૷Λ௥ͬͯΈΔ • ػೳΛ௥Ճ͢Δ •

    ·ͱΊ
  7. ϩʔΧϧϑΝΠϧɾΞηοτͷ࠶ੜ class LocalVideo extends StatefulWidget { @overrid e _LocalVideoState createState()

    => _LocalVideoState() ; } class _LocalVideoState extends State<LocalVideo> { late VideoPlayerController _controller ; @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.asset('assets/Butterfly-209.mp4') ; // _controller = VideoPlayerController.file(File('file path')) ; _controller.initialize() ; _controller.play() ; } @overrid e void dispose() { _controller.dispose() ; super.dispose() ; } @overrid e Widget build(BuildContext context) { return … VideoPlayer(_controller) ; … } }
  8. ϩʔΧϧϑΝΠϧɾΞηοτͷ࠶ੜ class LocalVideo extends StatefulWidget { @overrid e _LocalVideoState createState()

    => _LocalVideoState() ; } class _LocalVideoState extends State<LocalVideo> { late VideoPlayerController _controller ; @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.asset('assets/Butterfly-209.mp4') ; // _controller = VideoPlayerController.file(File('file path')) ; _controller.initialize() ; _controller.play() ; } @overrid e void dispose() { _controller.dispose() ; super.dispose() ; } @overrid e Widget build(BuildContext context) { return … VideoPlayer(_controller) ; … } }
  9. ϩʔΧϧϑΝΠϧɾΞηοτͷ࠶ੜ class LocalVideo extends StatefulWidget { @overrid e _LocalVideoState createState()

    => _LocalVideoState() ; } class _LocalVideoState extends State<LocalVideo> { late VideoPlayerController _controller ; @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.asset('assets/Butterfly-209.mp4') ; // _controller = VideoPlayerController.file(File('file path')) ; _controller.initialize() ; _controller.play() ; } @overrid e void dispose() { _controller.dispose() ; super.dispose() ; } @overrid e Widget build(BuildContext context) { return … VideoPlayer(_controller) ; … } }
  10. ϩʔΧϧϑΝΠϧɾΞηοτͷ࠶ੜ class LocalVideo extends StatefulWidget { @overrid e _LocalVideoState createState()

    => _LocalVideoState() ; } class _LocalVideoState extends State<LocalVideo> { late VideoPlayerController _controller ; @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.asset('assets/Butterfly-209.mp4') ; // _controller = VideoPlayerController.file(File('file path')) ; _controller.initialize() ; _controller.play() ; } @overrid e void dispose() { _controller.dispose() ; super.dispose() ; } @overrid e Widget build(BuildContext context) { return … VideoPlayer(_controller) ; … } }
  11. ϩʔΧϧϑΝΠϧɾΞηοτͷ࠶ੜ class LocalVideo extends StatefulWidget { @overrid e _LocalVideoState createState()

    => _LocalVideoState() ; } class _LocalVideoState extends State<LocalVideo> { late VideoPlayerController _controller ; @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.asset('assets/Butterfly-209.mp4') ; // _controller = VideoPlayerController.file(File('file path')) ; _controller.initialize() ; _controller.play() ; } @overrid e void dispose() { _controller.dispose() ; super.dispose() ; } @overrid e Widget build(BuildContext context) { return … VideoPlayer(_controller) ; … } }
  12. ϩʔΧϧϑΝΠϧɾΞηοτͷ࠶ੜ class LocalVideo extends StatefulWidget { @overrid e _LocalVideoState createState()

    => _LocalVideoState() ; } class _LocalVideoState extends State<LocalVideo> { late VideoPlayerController _controller ; @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.asset('assets/Butterfly-209.mp4') ; // _controller = VideoPlayerController.file(File('file path')) ; _controller.initialize() ; _controller.play() ; } @overrid e void dispose() { _controller.dispose() ; super.dispose() ; } @overrid e Widget build(BuildContext context) { return … VideoPlayer(_controller) ; … } }
  13. ϦϞʔτϑΝΠϧͷ࠶ੜ class RemoteVideo extends StatefulWidget { @overrid e _RemoteVideoState createState()

    => _RemoteVideoState() ; } class _RemoteVideoState extends State<RemoteVideo> { late VideoPlayerController _controller ; @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.network('https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4') ; _controller.initialize() ; _controller.play() ; } @overrid e void dispose() { _controller.dispose() ; super.dispose() ; } @overrid e Widget build(BuildContext context) { return … VideoPlayer(_controller) ; … } }
  14. ϦϞʔτϑΝΠϧͷ࠶ੜ class RemoteVideo extends StatefulWidget { @overrid e _RemoteVideoState createState()

    => _RemoteVideoState() ; } class _RemoteVideoState extends State<RemoteVideo> { late VideoPlayerController _controller ; @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.network('https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4') ; _controller.initialize() ; _controller.play() ; } @overrid e void dispose() { _controller.dispose() ; super.dispose() ; } @overrid e Widget build(BuildContext context) { return … VideoPlayer(_controller) ; … } }
  15. ϦϞʔτϑΝΠϧͷ࠶ੜ class RemoteVideo extends StatefulWidget { @overrid e _RemoteVideoState createState()

    => _RemoteVideoState() ; } class _RemoteVideoState extends State<RemoteVideo> { late VideoPlayerController _controller ; @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.network('https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8') ; _controller.initialize() ; _controller.play() ; } @overrid e void dispose() { _controller.dispose() ; super.dispose() ; } @overrid e Widget build(BuildContext context) { return … VideoPlayer(_controller) ; … } }
  16. ग़དྷΔ͜ͱ • ࠶ੜʗఀࢭʗγʔΫ • ϧʔϓ࠶ੜ • ϘϦϡʔϜઃఆ • ࠶ੜ଎౓ઃఆ

  17. ʴЋ • ࣈນ • γʔΫόʔ • ϥΠϑαΠΫϧʹ߹Θͤͯ࠶ੜʗఀࢭ

  18. ʴЋ • ࣈນ • γʔΫόʔ • ϥΠϑαΠΫϧʹ߹Θͤͯ࠶ੜʗఀࢭ

  19. ࣈນ class RemoteVideo extends StatefulWidget { … } class _RemoteVideoState

    extends State<RemoteVideo> { late VideoPlayerController _controller ; Future<ClosedCaptionFile> _loadCaptions() async { final String fileContents = await DefaultAssetBundle.of(context).loadString('assets/bumble_bee_captions.srt') ; return SubRipCaptionFile(fileContents) ; } @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.network ( 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4' , closedCaptionFile: _loadCaptions() , ) ; _controller.initialize() ; _controller.play() ; } … @overrid e Widget build(BuildContext context) { return … Stack ( children: <Widget> [ VideoPlayer(_controller) , ClosedCaption(text: _controller.value.caption.text) , ] , ) ; … } }
  20. ࣈນ class RemoteVideo extends StatefulWidget { … } class _RemoteVideoState

    extends State<RemoteVideo> { late VideoPlayerController _controller ; Future<ClosedCaptionFile> _loadCaptions() async { final String fileContents = await DefaultAssetBundle.of(context).loadString('assets/bumble_bee_captions.srt') ; return SubRipCaptionFile(fileContents) ; } @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.network ( 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4' , closedCaptionFile: _loadCaptions() , ) ; _controller.initialize() ; _controller.play() ; } … @overrid e Widget build(BuildContext context) { return … Stack ( children: <Widget> [ VideoPlayer(_controller) , ClosedCaption(text: _controller.value.caption.text) , ] , ) ; … } }
  21. ࣈນ class RemoteVideo extends StatefulWidget { … } class _RemoteVideoState

    extends State<RemoteVideo> { late VideoPlayerController _controller ; Future<ClosedCaptionFile> _loadCaptions() async { final String fileContents = await DefaultAssetBundle.of(context).loadString('assets/bumble_bee_captions.srt') ; return SubRipCaptionFile(fileContents) ; } @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.network ( 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4' , closedCaptionFile: _loadCaptions() , ) ; _controller.initialize() ; _controller.play() ; } … @overrid e Widget build(BuildContext context) { return … Stack ( children: <Widget> [ VideoPlayer(_controller) , ClosedCaption(text: _controller.value.caption.text) , ] , ) ; … } }
  22. ࣈນ class RemoteVideo extends StatefulWidget { … } class _RemoteVideoState

    extends State<RemoteVideo> { late VideoPlayerController _controller ; Future<ClosedCaptionFile> _loadCaptions() async { final String fileContents = await DefaultAssetBundle.of(context).loadString('assets/bumble_bee_captions.srt') ; return SubRipCaptionFile(fileContents) ; } @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.network ( 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4' , closedCaptionFile: _loadCaptions() , ) ; _controller.initialize() ; _controller.play() ; } … @overrid e Widget build(BuildContext context) { return … Stack ( children: <Widget> [ VideoPlayer(_controller) , ClosedCaption(text: _controller.value.caption.text) , ] , ) ; … } }
  23. ࣈນ • ϩʔΧϧϑΝΠϧ͔ΒಡΈࠐΉ͚ͩ • ετϦʔϜ͔Βड͚औΔ৔߹͸ผ్࣮૷͕ඞཁ • SRTʹରԠ • WebVTT͸1೥͘Β͍͔͚ͯઈࢍϨϏϡʔத fl

    utter/plugins#2878
  24. ʴЋ • ࣈນ • γʔΫόʔ • ϥΠϑαΠΫϧʹ߹Θͤͯ࠶ੜʗఀࢭ

  25. γʔΫόʔ class RemoteVideo extends StatefulWidget { … } class _RemoteVideoState

    extends State<RemoteVideo> { late VideoPlayerController _controller ; @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.network('https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4') ; _controller.initialize() ; _controller.play() ; } … @overrid e Widget build(BuildContext context) { return … Stack ( alignment: Alignment.bottomCenter , children: <Widget> [ VideoPlayer(_controller) , VideoProgressIndicator(_controller, allowScrubbing: true) , ] , ) ; … } }
  26. γʔΫόʔ class RemoteVideo extends StatefulWidget { … } class _RemoteVideoState

    extends State<RemoteVideo> { late VideoPlayerController _controller ; @overrid e void initState() { super.initState() ; _controller = VideoPlayerController.network('https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4') ; _controller.initialize() ; _controller.play() ; } … @overrid e Widget build(BuildContext context) { return … Stack ( alignment: Alignment.bottomCenter , children: <Widget> [ VideoPlayer(_controller) , VideoProgressIndicator(_controller, allowScrubbing: true) , ] , ) ; … } }
  27. γʔΫόʔ • ΧελϚΠζੑ௿͍͚ͲαΫοͱ͍͍ײ͡ʹͰ͖Δ

  28. ʴЋ • ࣈນ • γʔΫόʔ • ϥΠϑαΠΫϧʹ߹Θͤͯ࠶ੜʗఀࢭ

  29. ϥΠϑαΠΫϧʹ߹Θͤͯ࠶ੜʗఀࢭ class _VideoAppLifeCycleObserver extends Object with WidgetsBindingObserver { _VideoAppLifeCycleObserver(this._controller) ;

    bool _wasPlayingBeforePause = false ; final VideoPlayerController _controller ; void initialize() { WidgetsBinding.instance!.addObserver(this) ; } @overrid e void didChangeAppLifecycleState(AppLifecycleState state) { switch (state) { case AppLifecycleState.paused : _wasPlayingBeforePause = _controller.value.isPlaying ; _controller.pause() ; break ; case AppLifecycleState.resumed : if (_wasPlayingBeforePause) { _controller.play() ; } break ; default : } } void dispose() { WidgetsBinding.instance!.removeObserver(this) ; } }
  30. ϥΠϑαΠΫϧʹ߹Θͤͯ࠶ੜʗఀࢭ class _VideoAppLifeCycleObserver extends Object with WidgetsBindingObserver { _VideoAppLifeCycleObserver(this._controller) ;

    bool _wasPlayingBeforePause = false ; final VideoPlayerController _controller ; void initialize() { WidgetsBinding.instance!.addObserver(this) ; } @overrid e void didChangeAppLifecycleState(AppLifecycleState state) { switch (state) { case AppLifecycleState.paused : _wasPlayingBeforePause = _controller.value.isPlaying ; _controller.pause() ; break ; case AppLifecycleState.resumed : if (_wasPlayingBeforePause) { _controller.play() ; } break ; default : } } void dispose() { WidgetsBinding.instance!.removeObserver(this) ; } }
  31. Α͠ͳʹ΍ͬͯ͘Εͦ͏͚ͩͲ…

  32. ग़དྷͳ͍͜ͱ • ը࣭ઃఆ • ϏοτϨʔτΛઃఆͰ͖ͳ͍ • ࣈນɾ෭Ի੠ • ετϦʔϜʹ৐ͬͯΔࣈນɾԻ੠ͷऔಘɺબ୒͕Ͱ͖ͳ͍ •

    UI • ࣗ෼Ͱ࣮૷͢Δඞཁ͕͋Δ • DRM fl utter#24923 • Cookieͷઃఆ • ʢΤϥʔϋϯυϦϯάʣ
  33. ग़དྷͳ͍͜ͱ • ը࣭ઃఆ • ϏοτϨʔτΛઃఆͰ͖ͳ͍ • ࣈນɾ෭Ի੠ • ετϦʔϜʹ৐ͬͯΔࣈນɾԻ੠ͷऔಘɺબ୒͕Ͱ͖ͳ͍ •

    UI • ࣗ෼Ͱ࣮૷͢Δඞཁ͕͋Δ • DRM fl utter#24923 • Cookieͷઃఆ • ʢΤϥʔϋϯυϦϯάʣ
  34. ग़དྷͳ͍͜ͱ • ը࣭ઃఆ • ϏοτϨʔτΛઃఆͰ͖ͳ͍ • ࣈນɾ෭Ի੠ • ετϦʔϜʹ৐ͬͯΔࣈນɾԻ੠ͷऔಘɺબ୒͕Ͱ͖ͳ͍ •

    UI • ࣗ෼Ͱ࣮૷͢Δඞཁ͕͋Δ • DRM fl utter#24923 • Cookieͷઃఆ • ʢΤϥʔϋϯυϦϯάʣ
  35. ग़དྷͳ͍͜ͱ • ը࣭ઃఆ • ϏοτϨʔτΛઃఆͰ͖ͳ͍ • ࣈນɾ෭Ի੠ • ετϦʔϜʹ৐ͬͯΔࣈນɾԻ੠ͷऔಘɺબ୒͕Ͱ͖ͳ͍ •

    UI • ࣗ෼Ͱ࣮૷͢Δඞཁ͕͋Δ • DRM fl utter#24923 • Cookieͷઃఆ • ʢΤϥʔϋϯυϦϯάʣ
  36. ग़དྷͳ͍͜ͱ • ը࣭ઃఆ • ϏοτϨʔτΛઃఆͰ͖ͳ͍ • ࣈນɾ෭Ի੠ • ετϦʔϜʹ৐ͬͯΔࣈນɾԻ੠ͷऔಘɺબ୒͕Ͱ͖ͳ͍ •

    UI • ࣗ෼Ͱ࣮૷͢Δඞཁ͕͋Δ • DRM fl utter#24923 • Cookieͷઃఆ • ʢΤϥʔϋϯυϦϯάʣ
  37. ग़དྷͳ͍͜ͱ • ը࣭ઃఆ • ϏοτϨʔτΛઃఆͰ͖ͳ͍ • ࣈນɾ෭Ի੠ • ετϦʔϜʹ৐ͬͯΔࣈນɾԻ੠ͷऔಘɺબ୒͕Ͱ͖ͳ͍ •

    UI • ࣗ෼Ͱ࣮૷͢Δඞཁ͕͋Δ • DRM fl utter#24923 • Cookieͷઃఆ • ʢΤϥʔϋϯυϦϯάʣ
  38. Cookieͷઃఆ • AVURLAssetੜ੒࣌ʹcookieΛ౉͍ͨ͠৔߹ • issueɾPR͸ͪΐ͍ͪΐ͍ग़ͯΔ fl utter/plugins#2882 • react-nativeͰ͸Ϛʔδ͞Ε͍ͯΔ •

    react-native-video/react-native-video#2014 • fl utter/plugins#897 (comment) • AVURLAsset(url: url, options: [AVURLAssetHTTPCookiesKey: cookies])
  39. ग़དྷͳ͍͜ͱ • ը࣭ઃఆ • ϏοτϨʔτΛઃఆͰ͖ͳ͍ • ࣈນɾ෭Ի੠ • ετϦʔϜʹ৐ͬͯΔࣈນɾԻ੠ͷऔಘɺબ୒͕Ͱ͖ͳ͍ •

    UI • ࣗ෼Ͱ࣮૷͢Δඞཁ͕͋Δ • DRM fl utter#24923 • Cookieͷઃఆ • ʢΤϥʔϋϯυϦϯάʣ
  40. ΤϥʔϋϯυϦϯά class VideoPlayerController extends ValueNotifier<VideoPlayerValue> { … } … class

    VideoPlayerValue { … final Duration duration ; final Duration position ; final Caption caption ; final List<DurationRange> buffered ; final bool isPlaying ; final bool isLooping ; final bool isBuffering ; final double volume ; final double playbackSpeed ; final String? errorDescription ; final Size size ; final bool isInitialized ; bool get hasError => errorDescription != null ; … }
  41. ΤϥʔϋϯυϦϯά class VideoPlayerController extends ValueNotifier<VideoPlayerValue> { … } … class

    VideoPlayerValue { … final Duration duration ; final Duration position ; final Caption caption ; final List<DurationRange> buffered ; final bool isPlaying ; final bool isLooping ; final bool isBuffering ; final double volume ; final double playbackSpeed ; final String? errorDescription ; final Size size ; final bool isInitialized ; bool get hasError => errorDescription != null ; … }
  42. ΤϥʔϋϯυϦϯά class VideoPlayerController extends ValueNotifier<VideoPlayerValue> { … } … class

    VideoPlayerValue { … final Duration duration ; final Duration position ; final Caption caption ; final List<DurationRange> buffered ; final bool isPlaying ; final bool isLooping ; final bool isBuffering ; final double volume ; final double playbackSpeed ; final String? errorDescription ; final Size size ; final bool isInitialized ; bool get hasError => errorDescription != null ; … }
  43. ΤϥʔϋϯυϦϯά // iO S _eventSink([FlutterError errorWithCode:@"VideoError" message:@"Video cannot be fast-forwarded

    beyond 2.0x" details:nil]) ; _eventSink([FlutterError errorWithCode:@"VideoError" message:[@"Failed to load video: “ stringByAppendingString:[item.error localizedDescription] ] details:nil]) ; // Androi d eventSink.error("VideoError", "Video player had error " + error, null);
  44. ΤϥʔϋϯυϦϯά // iO S … AVPlayerItem* item = (AVPlayerItem*)object ;

    switch (item.status) { case AVPlayerItemStatusFailed : if (_eventSink != nil) { _eventSink([FlutterError errorWithCode:@"VideoError" message:[@"Failed to load video: " stringByAppendingString:[item.error localizedDescription] ] details:nil]) ; } break ; case AVPlayerItemStatusUnknown : break ; case AVPlayerItemStatusReadyToPlay : [item addOutput:_videoOutput] ; [self sendInitialized] ; [self updatePlayingState] ; break ; } …
  45. ΤϥʔϋϯυϦϯά // iO S … AVPlayerItem* item = (AVPlayerItem*)object ;

    switch (item.status) { case AVPlayerItemStatusFailed : if (_eventSink != nil) { _eventSink([FlutterError errorWithCode:@"VideoError" message:[@"Failed to load video: " stringByAppendingString:[item.error localizedDescription] ] details:nil]) ; } break ; case AVPlayerItemStatusUnknown : break ; case AVPlayerItemStatusReadyToPlay : [item addOutput:_videoOutput] ; [self sendInitialized] ; [self updatePlayingState] ; break ; } …
  46. ΤϥʔϋϯυϦϯά // Androi d exoPlayer.addListener ( new EventListener() { …

    @Overrid e public void onPlayerError(final ExoPlaybackException error) { setBuffering(false) ; if (eventSink != null) { eventSink.error("VideoError", "Video player had error " + error, null) ; } } }) ;
  47. ΤϥʔϋϯυϦϯά // Androi d exoPlayer.addListener ( new EventListener() { …

    @Overrid e public void onPlayerError(final ExoPlaybackException error) { setBuffering(false) ; if (eventSink != null) { eventSink.error("VideoError", "Video player had error " + error, null) ; } } }) ;
  48. ΤϥʔϋϯυϦϯά • ग़དྷͳ͍Θ͚Ͱ͸ͳ͍ • isBuffering౳ݟΕ͹े෼ͳ৔߹΋ • ࡉ͔͘ϋϯυϦϯά͚ͨ͠Ε͹࣮૷͢Δ͔͠ͳͦ͞͏

  49. ໨࣍ • ύοέʔδͷ঺հ • video_playerʹ͍ͭͯ • ࣮૷Λ௥ͬͯΈΔ • ػೳΛ௥Ճ͢Δ •

    ·ͱΊ
  50. جຊతͳ࢓૊Έ • BasicMessageChannelͱEventChannelͷ૊Έ߹Θͤ • BasicMessageChannelɿϓϥοτϑΥʔϜͱDartؒͰ૒ํ޲ʹϝοηʔδ Λૹड৴͢ΔͨΊͷAPI • EventChannelɿϓϥοτϑΥʔϜ͔ΒDartଆʹΠϕϯτ௨஌͢ΔͨΊͷAPI video_player_platform_interface video_player

    EventChannel BasicMessageChannel
  51. EventChannel initialized completed bu ff eringStart bu ff eringUpdate bu

    ff eringEnd video_player_platform_interface video_player Stream EventChannel
  52. BasicMessageChannel video_player_platform_interface video_player getPosition(_:) send replay Future<Duration> ྫ

  53. BasicMessageChannel video_player_platform_interface video_player getPosition(_:) send replay Future<Duration> ྫ

  54. BasicMessageChannel video_player_platform_interface video_player getPosition(_:) send replay Future<Duration> ྫ

  55. BasicMessageChannel video_player_platform_interface video_player getPosition(_:) send replay Future<Duration> ྫ

  56. BasicMessageChannel video_player_platform_interface video_player getPosition(_:) send replay Future<Duration> ྫ

  57. BasicMessageChannel Future<PositionMessage> position(TextureMessage arg) async { final Object encoded =

    arg.encode() ; const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?> ( 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()) ; final Map<Object?, Object?>? replyMap = await channel.send(encoded) as Map<Object?, Object?>? ; if (replyMap == null) { throw PlatformException ( code: 'channel-error' , message: 'Unable to establish connection on channel.' , details: null , ) ; } else if (replyMap['error'] != null) { final Map<Object?, Object?> error = replyMap['error'] as Map<Object?, Object?> ; throw PlatformException ( code: error['code'] as String , message: error['message'] as String? , details: error['details'] , ) ; } else { return PositionMessage.decode(replyMap['result']!) ; } }
  58. BasicMessageChannel Future<PositionMessage> position(TextureMessage arg) async { final Object encoded =

    arg.encode() ; const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?> ( 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()) ; final Map<Object?, Object?>? replyMap = await channel.send(encoded) as Map<Object?, Object?>? ; if (replyMap == null) { throw PlatformException ( code: 'channel-error' , message: 'Unable to establish connection on channel.' , details: null , ) ; } else if (replyMap['error'] != null) { final Map<Object?, Object?> error = replyMap['error'] as Map<Object?, Object?> ; throw PlatformException ( code: error['code'] as String , message: error['message'] as String? , details: error['details'] , ) ; } else { return PositionMessage.decode(replyMap['result']!) ; } } class TextureMessage { int? textureId ; Object encode() { final Map<Object?, Object?> pigeonMap = <Object?, Object?>{} ; pigeonMap['textureId'] = textureId ; return pigeonMap ; } static TextureMessage decode(Object message) { final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?> ; return TextureMessage()..textureId = pigeonMap['textureId'] as int ; } }
  59. BasicMessageChannel Future<PositionMessage> position(TextureMessage arg) async { final Object encoded =

    arg.encode() ; const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?> ( 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()) ; final Map<Object?, Object?>? replyMap = await channel.send(encoded) as Map<Object?, Object?>? ; if (replyMap == null) { throw PlatformException ( code: 'channel-error' , message: 'Unable to establish connection on channel.' , details: null , ) ; } else if (replyMap['error'] != null) { final Map<Object?, Object?> error = replyMap['error'] as Map<Object?, Object?> ; throw PlatformException ( code: error['code'] as String , message: error['message'] as String? , details: error['details'] , ) ; } else { return PositionMessage.decode(replyMap['result']!) ; } } class TextureMessage { int? textureId ; Object encode() { final Map<Object?, Object?> pigeonMap = <Object?, Object?>{} ; pigeonMap['textureId'] = textureId ; return pigeonMap ; } static TextureMessage decode(Object message) { final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?> ; return TextureMessage()..textureId = pigeonMap['textureId'] as int ; } }
  60. BasicMessageChannel Future<PositionMessage> position(TextureMessage arg) async { final Object encoded =

    arg.encode() ; const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?> ( 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()) ; final Map<Object?, Object?>? replyMap = await channel.send(encoded) as Map<Object?, Object?>? ; if (replyMap == null) { throw PlatformException ( code: 'channel-error' , message: 'Unable to establish connection on channel.' , details: null , ) ; } else if (replyMap['error'] != null) { final Map<Object?, Object?> error = replyMap['error'] as Map<Object?, Object?> ; throw PlatformException ( code: error['code'] as String , message: error['message'] as String? , details: error['details'] , ) ; } else { return PositionMessage.decode(replyMap['result']!) ; } } class TextureMessage { int? textureId ; Object encode() { final Map<Object?, Object?> pigeonMap = <Object?, Object?>{} ; pigeonMap['textureId'] = textureId ; return pigeonMap ; } static TextureMessage decode(Object message) { final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?> ; return TextureMessage()..textureId = pigeonMap['textureId'] as int ; } }
  61. BasicMessageChannel Future<PositionMessage> position(TextureMessage arg) async { final Object encoded =

    arg.encode() ; const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?> ( 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()) ; final Map<Object?, Object?>? replyMap = await channel.send(encoded) as Map<Object?, Object?>? ; if (replyMap == null) { throw PlatformException ( code: 'channel-error' , message: 'Unable to establish connection on channel.' , details: null , ) ; } else if (replyMap['error'] != null) { final Map<Object?, Object?> error = replyMap['error'] as Map<Object?, Object?> ; throw PlatformException ( code: error['code'] as String , message: error['message'] as String? , details: error['details'] , ) ; } else { return PositionMessage.decode(replyMap['result']!) ; } } class TextureMessage { int? textureId ; Object encode() { final Map<Object?, Object?> pigeonMap = <Object?, Object?>{} ; pigeonMap['textureId'] = textureId ; return pigeonMap ; } static TextureMessage decode(Object message) { final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?> ; return TextureMessage()..textureId = pigeonMap['textureId'] as int ; } }
  62. BasicMessageChannel Future<PositionMessage> position(TextureMessage arg) async { final Object encoded =

    arg.encode() ; const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?> ( 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()) ; final Map<Object?, Object?>? replyMap = await channel.send(encoded) as Map<Object?, Object?>? ; if (replyMap == null) { throw PlatformException ( code: 'channel-error' , message: 'Unable to establish connection on channel.' , details: null , ) ; } else if (replyMap['error'] != null) { final Map<Object?, Object?> error = replyMap['error'] as Map<Object?, Object?> ; throw PlatformException ( code: error['code'] as String , message: error['message'] as String? , details: error['details'] , ) ; } else { return PositionMessage.decode(replyMap['result']!) ; } }
  63. BasicMessageChannel Future<PositionMessage> position(TextureMessage arg) async { final Object encoded =

    arg.encode() ; const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?> ( 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()) ; final Map<Object?, Object?>? replyMap = await channel.send(encoded) as Map<Object?, Object?>? ; if (replyMap == null) { throw PlatformException ( code: 'channel-error' , message: 'Unable to establish connection on channel.' , details: null , ) ; } else if (replyMap['error'] != null) { final Map<Object?, Object?> error = replyMap['error'] as Map<Object?, Object?> ; throw PlatformException ( code: error['code'] as String , message: error['message'] as String? , details: error['details'] , ) ; } else { return PositionMessage.decode(replyMap['result']!) ; } } Channel͸APIຖʹ࡞੒
  64. BasicMessageChannel Future<PositionMessage> position(TextureMessage arg) async { final Object encoded =

    arg.encode() ; const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?> ( 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()) ; final Map<Object?, Object?>? replyMap = await channel.send(encoded) as Map<Object?, Object?>? ; if (replyMap == null) { throw PlatformException ( code: 'channel-error' , message: 'Unable to establish connection on channel.' , details: null , ) ; } else if (replyMap['error'] != null) { final Map<Object?, Object?> error = replyMap['error'] as Map<Object?, Object?> ; throw PlatformException ( code: error['code'] as String , message: error['message'] as String? , details: error['details'] , ) ; } else { return PositionMessage.decode(replyMap['result']!) ; } }
  65. BasicMessageChannel Future<PositionMessage> position(TextureMessage arg) async { final Object encoded =

    arg.encode() ; const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?> ( 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()) ; final Map<Object?, Object?>? replyMap = await channel.send(encoded) as Map<Object?, Object?>? ; if (replyMap == null) { throw PlatformException ( code: 'channel-error' , message: 'Unable to establish connection on channel.' , details: null , ) ; } else if (replyMap['error'] != null) { final Map<Object?, Object?> error = replyMap['error'] as Map<Object?, Object?> ; throw PlatformException ( code: error['code'] as String , message: error['message'] as String? , details: error['details'] , ) ; } else { return PositionMessage.decode(replyMap['result']!) ; } }
  66. BasicMessageChannel Future<PositionMessage> position(TextureMessage arg) async { final Object encoded =

    arg.encode() ; const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?> ( 'dev.flutter.pigeon.VideoPlayerApi.position', StandardMessageCodec()) ; final Map<Object?, Object?>? replyMap = await channel.send(encoded) as Map<Object?, Object?>? ; if (replyMap == null) { throw PlatformException ( code: 'channel-error' , message: 'Unable to establish connection on channel.' , details: null , ) ; } else if (replyMap['error'] != null) { final Map<Object?, Object?> error = replyMap['error'] as Map<Object?, Object?> ; throw PlatformException ( code: error['code'] as String , message: error['message'] as String? , details: error['details'] , ) ; } else { return PositionMessage.decode(replyMap['result']!) ; } }
  67. ಈըͷඳը • PlatformView

  68. ಈըͷඳը • PlatformView

  69. ಈըͷඳը • PlatformView • Texture Widget • https://api. fl utter.dev/

    fl utter/widgets/Texture-class.html • ϓϥοτϑΥʔϜଆ͔ΒtextureIdΛड͚औΓɺϏσΦϑϨʔϜ౸ண ࣌౳ʹࣗಈతʹόοΫΤϯυͷࢦࣔʹैͬͯ࠶ඳը͞ΕΔ • ௨ৗɺDartίʔυͷ࣮ߦ͸ؚ·Εͳ͍
  70. ಈըͷඳը • Dart • iOS • Android

  71. ಈըͷඳը • Dart • iOS • Android

  72. Dart // VideoPlayerControlle r @overrid e Widget build(BuildContext context) {

    return _textureId == VideoPlayerController.kUninitializedTextureI d ? Container( ) : _videoPlayerPlatform.buildView(_textureId) ; } // video_player_platform_interfac e @overrid e Widget buildView(int textureId) { return Texture(textureId: textureId) ; }
  73. Dart // VideoPlayerControlle r @overrid e Widget build(BuildContext context) {

    return _textureId == VideoPlayerController.kUninitializedTextureI d ? Container( ) : _videoPlayerPlatform.buildView(_textureId) ; } // video_player_platform_interfac e @overrid e Widget buildView(int textureId) { return Texture(textureId: textureId) ; }
  74. Dart // VideoPlayerControlle r @overrid e Widget build(BuildContext context) {

    return _textureId == VideoPlayerController.kUninitializedTextureI d ? Container( ) : _videoPlayerPlatform.buildView(_textureId) ; } // video_player_platform_interfac e @overrid e Widget buildView(int textureId) { return Texture(textureId: textureId) ; }
  75. ಈըͷඳը • Dart • iOS • Android

  76. iOS @protocol FlutterTexture <NSObject > /** Copy the contents of

    the texture into a `CVPixelBuffer`. */ - (CVPixelBufferRef _Nullable)copyPixelBuffer ; /** * Called when the texture is unregistered. * * Called on the raster thread. */ @optional - (void)onTextureUnregistered:(NSObject<FlutterTexture>*)texture ; @end FlutterTexture
  77. iOS @protocol FlutterTexture <NSObject > /** Copy the contents of

    the texture into a `CVPixelBuffer`. */ - (CVPixelBufferRef _Nullable)copyPixelBuffer ; /** * Called when the texture is unregistered. * * Called on the raster thread. */ @optional - (void)onTextureUnregistered:(NSObject<FlutterTexture>*)texture ; @end FlutterTexture
  78. iOS @protocol FlutterTexture <NSObject > /** Copy the contents of

    the texture into a `CVPixelBuffer`. */ - (CVPixelBufferRef _Nullable)copyPixelBuffer ; /** * Called when the texture is unregistered. * * Called on the raster thread. */ @optional - (void)onTextureUnregistered:(NSObject<FlutterTexture>*)texture ; @end FlutterTexture - (CVPixelBufferRef)copyPixelBuffer { CMTime outputItemTime = [_videoOutput itemTimeForHostTime:CACurrentMediaTime()] ; if ([_videoOutput hasNewPixelBufferForItemTime:outputItemTime]) { return [_videoOutput copyPixelBufferForItemTime:outputItemTime itemTimeForDisplay:NULL] ; } else { return NULL ; } }
  79. iOS @protocol FlutterTexture <NSObject > /** Copy the contents of

    the texture into a `CVPixelBuffer`. */ - (CVPixelBufferRef _Nullable)copyPixelBuffer ; /** * Called when the texture is unregistered. * * Called on the raster thread. */ @optional - (void)onTextureUnregistered:(NSObject<FlutterTexture>*)texture ; @end FlutterTexture - (CVPixelBufferRef)copyPixelBuffer { CMTime outputItemTime = [_videoOutput itemTimeForHostTime:CACurrentMediaTime()] ; if ([_videoOutput hasNewPixelBufferForItemTime:outputItemTime]) { return [_videoOutput copyPixelBufferForItemTime:outputItemTime itemTimeForDisplay:NULL] ; } else { return NULL ; } }
  80. iOS @protocol FlutterTexture <NSObject > /** Copy the contents of

    the texture into a `CVPixelBuffer`. */ - (CVPixelBufferRef _Nullable)copyPixelBuffer ; /** * Called when the texture is unregistered. * * Called on the raster thread. */ @optional - (void)onTextureUnregistered:(NSObject<FlutterTexture>*)texture ; @end FlutterTexture
  81. iOS @protocol FlutterTexture <NSObject > /** Copy the contents of

    the texture into a `CVPixelBuffer`. */ - (CVPixelBufferRef _Nullable)copyPixelBuffer ; /** * Called when the texture is unregistered. * * Called on the raster thread. */ @optional - (void)onTextureUnregistered:(NSObject<FlutterTexture>*)texture ; @end FlutterTexture - (void)onTextureUnregistered:(NSObject<FlutterTexture>*)texture { dispatch_async(dispatch_get_main_queue(), ^ { [self dispose] ; }) ; }
  82. iOS @protocol FlutterTextureRegistry <NSObject > /** * Registers a `FlutterTexture`

    for usage in Flutter and returns an id that can be used to reference * that texture when calling into Flutter with channels. Textures must be registered on the * platform thread. */ - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture ; /** * Notifies Flutter that the content of the previously registered texture has been updated. * * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. */ - (void)textureFrameAvailable:(int64_t)textureId ; /** * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures * must be unregistered on the the platform thread. * * @param textureId The result that was previously returned from `registerTexture:`. */ - (void)unregisterTexture:(int64_t)textureId ; @end FlutterTextureRegistry
  83. iOS @protocol FlutterTextureRegistry <NSObject > /** * Registers a `FlutterTexture`

    for usage in Flutter and returns an id that can be used to reference * that texture when calling into Flutter with channels. Textures must be registered on the * platform thread. */ - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture ; /** * Notifies Flutter that the content of the previously registered texture has been updated. * * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. */ - (void)textureFrameAvailable:(int64_t)textureId ; /** * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures * must be unregistered on the the platform thread. * * @param textureId The result that was previously returned from `registerTexture:`. */ - (void)unregisterTexture:(int64_t)textureId ; @end FlutterTextureRegistry
  84. iOS @protocol FlutterTextureRegistry <NSObject > /** * Registers a `FlutterTexture`

    for usage in Flutter and returns an id that can be used to reference * that texture when calling into Flutter with channels. Textures must be registered on the * platform thread. */ - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture ; /** * Notifies Flutter that the content of the previously registered texture has been updated. * * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. */ - (void)textureFrameAvailable:(int64_t)textureId ; /** * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures * must be unregistered on the the platform thread. * * @param textureId The result that was previously returned from `registerTexture:`. */ - (void)unregisterTexture:(int64_t)textureId ; @end FlutterTextureRegistry … int64_t textureId = [_registry registerTexture:player] ; …
  85. iOS @protocol FlutterTextureRegistry <NSObject > /** * Registers a `FlutterTexture`

    for usage in Flutter and returns an id that can be used to reference * that texture when calling into Flutter with channels. Textures must be registered on the * platform thread. */ - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture ; /** * Notifies Flutter that the content of the previously registered texture has been updated. * * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. */ - (void)textureFrameAvailable:(int64_t)textureId ; /** * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures * must be unregistered on the the platform thread. * * @param textureId The result that was previously returned from `registerTexture:`. */ - (void)unregisterTexture:(int64_t)textureId ; @end FlutterTextureRegistry … int64_t textureId = [_registry registerTexture:player] ; … textureId͕ฦΔ
  86. iOS @protocol FlutterTextureRegistry <NSObject > /** * Registers a `FlutterTexture`

    for usage in Flutter and returns an id that can be used to reference * that texture when calling into Flutter with channels. Textures must be registered on the * platform thread. */ - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture ; /** * Notifies Flutter that the content of the previously registered texture has been updated. * * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. */ - (void)textureFrameAvailable:(int64_t)textureId ; /** * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures * must be unregistered on the the platform thread. * * @param textureId The result that was previously returned from `registerTexture:`. */ - (void)unregisterTexture:(int64_t)textureId ; @end FlutterTextureRegistry
  87. iOS @protocol FlutterTextureRegistry <NSObject > /** * Registers a `FlutterTexture`

    for usage in Flutter and returns an id that can be used to reference * that texture when calling into Flutter with channels. Textures must be registered on the * platform thread. */ - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture ; /** * Notifies Flutter that the content of the previously registered texture has been updated. * * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. */ - (void)textureFrameAvailable:(int64_t)textureId ; /** * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures * must be unregistered on the the platform thread. * * @param textureId The result that was previously returned from `registerTexture:`. */ - (void)unregisterTexture:(int64_t)textureId ; @end FlutterTextureRegistry • FlutterʹTexture͕ߋ৽͞Εͨͱ఻͑Δ • FlutterTexture.copyPixcelBu ff er()͕ݺͼ͞ΕΔ
  88. iOS @protocol FlutterTextureRegistry <NSObject > /** * Registers a `FlutterTexture`

    for usage in Flutter and returns an id that can be used to reference * that texture when calling into Flutter with channels. Textures must be registered on the * platform thread. */ - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture ; /** * Notifies Flutter that the content of the previously registered texture has been updated. * * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. */ - (void)textureFrameAvailable:(int64_t)textureId ; /** * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures * must be unregistered on the the platform thread. * * @param textureId The result that was previously returned from `registerTexture:`. */ - (void)unregisterTexture:(int64_t)textureId ; @end FlutterTextureRegistry _displayLink = [CADisplayLink displayLinkWithTarget:frameUpdate r selector:@selector(onDisplayLink:)] ; . .. - (void)onDisplayLink:(CADisplayLink*)link { [_registry textureFrameAvailable:_textureId] ; }
  89. iOS @protocol FlutterTextureRegistry <NSObject > /** * Registers a `FlutterTexture`

    for usage in Flutter and returns an id that can be used to reference * that texture when calling into Flutter with channels. Textures must be registered on the * platform thread. */ - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture ; /** * Notifies Flutter that the content of the previously registered texture has been updated. * * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. */ - (void)textureFrameAvailable:(int64_t)textureId ; /** * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures * must be unregistered on the the platform thread. * * @param textureId The result that was previously returned from `registerTexture:`. */ - (void)unregisterTexture:(int64_t)textureId ; @end FlutterTextureRegistry _displayLink = [CADisplayLink displayLinkWithTarget:frameUpdate r selector:@selector(onDisplayLink:)] ; . .. - (void)onDisplayLink:(CADisplayLink*)link { [_registry textureFrameAvailable:_textureId] ; }
  90. iOS @protocol FlutterTextureRegistry <NSObject > /** * Registers a `FlutterTexture`

    for usage in Flutter and returns an id that can be used to reference * that texture when calling into Flutter with channels. Textures must be registered on the * platform thread. */ - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture ; /** * Notifies Flutter that the content of the previously registered texture has been updated. * * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. */ - (void)textureFrameAvailable:(int64_t)textureId ; /** * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures * must be unregistered on the the platform thread. * * @param textureId The result that was previously returned from `registerTexture:`. */ - (void)unregisterTexture:(int64_t)textureId ; @end FlutterTextureRegistry _displayLink = [CADisplayLink displayLinkWithTarget:frameUpdate r selector:@selector(onDisplayLink:)] ; . .. - (void)onDisplayLink:(CADisplayLink*)link { [_registry textureFrameAvailable:_textureId] ; }
  91. iOS @protocol FlutterTextureRegistry <NSObject > /** * Registers a `FlutterTexture`

    for usage in Flutter and returns an id that can be used to reference * that texture when calling into Flutter with channels. Textures must be registered on the * platform thread. */ - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture ; /** * Notifies Flutter that the content of the previously registered texture has been updated. * * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. */ - (void)textureFrameAvailable:(int64_t)textureId ; /** * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures * must be unregistered on the the platform thread. * * @param textureId The result that was previously returned from `registerTexture:`. */ - (void)unregisterTexture:(int64_t)textureId ; @end FlutterTextureRegistry
  92. iOS @protocol FlutterTextureRegistry <NSObject > /** * Registers a `FlutterTexture`

    for usage in Flutter and returns an id that can be used to reference * that texture when calling into Flutter with channels. Textures must be registered on the * platform thread. */ - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture ; /** * Notifies Flutter that the content of the previously registered texture has been updated. * * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. */ - (void)textureFrameAvailable:(int64_t)textureId ; /** * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures * must be unregistered on the the platform thread. * * @param textureId The result that was previously returned from `registerTexture:`. */ - (void)unregisterTexture:(int64_t)textureId ; @end FlutterTextureRegistry - (void)dispose:(FLTTextureMessage*)input error:(FlutterError**)error { … [_registry unregisterTexture:input.textureId.intValue];
  93. ಈըͷඳը • Dart • iOS • Android

  94. Android public interface TextureRegistry { /* * * Creates and

    registers a SurfaceTexture managed by the Flutter engine . * * @return A SurfaceTextureEntry . * / SurfaceTextureEntry createSurfaceTexture() ; /** A registry entry for a managed SurfaceTexture. * / interface SurfaceTextureEntry { /** @return The managed SurfaceTexture. * / SurfaceTexture surfaceTexture() ; /** @return The identity of this SurfaceTexture. * / long id() ; /** Deregisters and releases this SurfaceTexture. * / void release() ; } } TextureRegistry
  95. Android public interface TextureRegistry { /* * * Creates and

    registers a SurfaceTexture managed by the Flutter engine . * * @return A SurfaceTextureEntry . * / SurfaceTextureEntry createSurfaceTexture() ; /** A registry entry for a managed SurfaceTexture. * / interface SurfaceTextureEntry { /** @return The managed SurfaceTexture. * / SurfaceTexture surfaceTexture() ; /** @return The identity of this SurfaceTexture. * / long id() ; /** Deregisters and releases this SurfaceTexture. * / void release() ; } } TextureRegistry
  96. Android public interface TextureRegistry { /* * * Creates and

    registers a SurfaceTexture managed by the Flutter engine . * * @return A SurfaceTextureEntry . * / SurfaceTextureEntry createSurfaceTexture() ; /** A registry entry for a managed SurfaceTexture. * / interface SurfaceTextureEntry { /** @return The managed SurfaceTexture. * / SurfaceTexture surfaceTexture() ; /** @return The identity of this SurfaceTexture. * / long id() ; /** Deregisters and releases this SurfaceTexture. * / void release() ; } } TextureRegistry .. . TextureRegistry.SurfaceTextureEntry handle = flutterState.textureRegistry.createSurfaceTexture() ; ...
  97. Android public interface TextureRegistry { /* * * Creates and

    registers a SurfaceTexture managed by the Flutter engine . * * @return A SurfaceTextureEntry . * / SurfaceTextureEntry createSurfaceTexture() ; /** A registry entry for a managed SurfaceTexture. * / interface SurfaceTextureEntry { /** @return The managed SurfaceTexture. * / SurfaceTexture surfaceTexture() ; /** @return The identity of this SurfaceTexture. * / long id() ; /** Deregisters and releases this SurfaceTexture. * / void release() ; } } TextureRegistry
  98. Android public interface TextureRegistry { /* * * Creates and

    registers a SurfaceTexture managed by the Flutter engine . * * @return A SurfaceTextureEntry . * / SurfaceTextureEntry createSurfaceTexture() ; /** A registry entry for a managed SurfaceTexture. * / interface SurfaceTextureEntry { /** @return The managed SurfaceTexture. * / SurfaceTexture surfaceTexture() ; /** @return The identity of this SurfaceTexture. * / long id() ; /** Deregisters and releases this SurfaceTexture. * / void release() ; } } TextureRegistry ... surface = new Surface(textureEntry.surfaceTexture()) ; exoPlayer.setVideoSurface(surface) ; ...
  99. Android public interface TextureRegistry { /* * * Creates and

    registers a SurfaceTexture managed by the Flutter engine . * * @return A SurfaceTextureEntry . * / SurfaceTextureEntry createSurfaceTexture() ; /** A registry entry for a managed SurfaceTexture. * / interface SurfaceTextureEntry { /** @return The managed SurfaceTexture. * / SurfaceTexture surfaceTexture() ; /** @return The identity of this SurfaceTexture. * / long id() ; /** Deregisters and releases this SurfaceTexture. * / void release() ; } } TextureRegistry
  100. Android public interface TextureRegistry { /* * * Creates and

    registers a SurfaceTexture managed by the Flutter engine . * * @return A SurfaceTextureEntry . * / SurfaceTextureEntry createSurfaceTexture() ; /** A registry entry for a managed SurfaceTexture. * / interface SurfaceTextureEntry { /** @return The managed SurfaceTexture. * / SurfaceTexture surfaceTexture() ; /** @return The identity of this SurfaceTexture. * / long id() ; /** Deregisters and releases this SurfaceTexture. * / void release() ; } } TextureRegistry textureId͕ฦΔ
  101. ໨࣍ • ύοέʔδͷ঺հ • video_playerʹ͍ͭͯ • ࣮૷Λ௥ͬͯΈΔ • ػೳΛ௥Ճ͢Δ •

    ·ͱΊ
  102. pigeon • pub.dev • GitHub • ϓϥοτϑΥʔϜͱDartͷ઀ଓ෦෼Λࣗಈੜ੒ͯ͘͠ΕΔ

  103. pigeon/messages.dart class LimitBitrateMessage { int textureId ; int limitBitrate ;

    } .. . abstract class VideoPlayerApi { void initialize() ; TextureMessage create(CreateMessage msg) ; void dispose(TextureMessage msg) ; void setLooping(LoopingMessage msg) ; void setVolume(VolumeMessage msg) ; void setPlaybackSpeed(PlaybackSpeedMessage msg) ; void play(TextureMessage msg) ; PositionMessage position(TextureMessage msg) ; void seekTo(PositionMessage msg) ; void pause(TextureMessage msg) ; void setMixWithOthers(MixWithOthersMessage msg) ; void setLimitBitrate(LimitBitrateMessage msg) ; }
  104. pigeon/messages.dart class LimitBitrateMessage { int textureId ; int limitBitrate ;

    } .. . abstract class VideoPlayerApi { void initialize() ; TextureMessage create(CreateMessage msg) ; void dispose(TextureMessage msg) ; void setLooping(LoopingMessage msg) ; void setVolume(VolumeMessage msg) ; void setPlaybackSpeed(PlaybackSpeedMessage msg) ; void play(TextureMessage msg) ; PositionMessage position(TextureMessage msg) ; void seekTo(PositionMessage msg) ; void pause(TextureMessage msg) ; void setMixWithOthers(MixWithOthersMessage msg) ; void setLimitBitrate(LimitBitrateMessage msg) ; }
  105. pigeon/messages.dart class LimitBitrateMessage { int textureId ; int limitBitrate ;

    } .. . abstract class VideoPlayerApi { void initialize() ; TextureMessage create(CreateMessage msg) ; void dispose(TextureMessage msg) ; void setLooping(LoopingMessage msg) ; void setVolume(VolumeMessage msg) ; void setPlaybackSpeed(PlaybackSpeedMessage msg) ; void play(TextureMessage msg) ; PositionMessage position(TextureMessage msg) ; void seekTo(PositionMessage msg) ; void pause(TextureMessage msg) ; void setMixWithOthers(MixWithOthersMessage msg) ; void setLimitBitrate(LimitBitrateMessage msg) ; }
  106. ϑΝΠϧͷੜ੒ $flutter pub run pigeon --input pigeons/messages.dart —dart_null_safet y $(cd

    ../../../; ./script/incremental_build.sh format --travis --clang-format=clang-format-7)
  107. ϑΝΠϧͷੜ੒ $flutter pub run pigeon --input pigeons/messages.dart —dart_null_safet y $(cd

    ../../../; ./script/incremental_build.sh format --travis --clang-format=clang-format-7)
  108. ϑΝΠϧͷੜ੒ $flutter pub run pigeon --input pigeons/messages.dart —dart_null_safet y $(cd

    ../../../; ./script/incremental_build.sh format --travis --clang-format=clang-format-7)
  109. ϑΝΠϧͷੜ੒ $flutter pub run pigeon --input pigeons/messages.dart —dart_null_safet y $(cd

    ../../../; ./script/incremental_build.sh format --travis --clang-format=clang-format-7) fl utter/plugin ಠࣗͷϑΥʔϚοτ
  110. ࣮૷͢Δ • iOS͸Objective-CɺAndroid͸JavaͰͦΕͧΕ࣮૷͢Δ

  111. ໨࣍ • ύοέʔδͷ঺հ • video_playerʹ͍ͭͯ • ࣮૷Λ௥ͬͯΈΔ • ػೳΛ௥Ճ͢Δ •

    ·ͱΊ
  112. ·ͱΊ • ΨνΨνͳཁ݅͡Όͳ͚Ε͹αΫοͱಋೖͰ͖ͦ͏ • Objective-CͱJava • ExoPlayerͷexampleॆ࣮ͯͨ͠

  113. ͋Γ͕ͱ͏͍͟͝·ͨ͠