flutter_youtube_view icon indicating copy to clipboard operation
flutter_youtube_view copied to clipboard

'loadPlayer()' is deprecated

Open komaromil opened this issue 2 years ago • 7 comments

/Users/laszlokomaromi/Documents/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_youtube_view-2.0.4/ios/Classes/FlutterYoutubeView.swift:169:21: 'loadPlayer()' is deprecated: renamed to 'loadPlayerHTML'

Please update

komaromil avatar Jun 04 '22 09:06 komaromil

Same problem for me, are they working on a solution?

Juanixou avatar Jun 21 '22 08:06 Juanixou

Same problem, app crashing in IOS... what is the solution please !

Majda-Labiadh avatar Jun 22 '22 08:06 Majda-Labiadh

Hi! I had the same problem. Even though I'm not a Swift developer, but I found this solution which I tested and works. There seems to be some kind of problem with the Bundle stuff...

in file: FlutterYoutubeView.swift line: 171 Add this code:


let htmlString: String? =
        """
        <!DOCTYPE html>
        <html>
        <head>
            <style>
                html, body { margin: 0; padding: 0; width: 100%; height: 100%; background-color: #000000; }
            </style>
        </head>
        <body>
            <div id="player"></div>
            <div id="explain"></div>
            <script src="https://www.youtube.com/iframe_api" onerror="webkit.messageHandlers.onYouTubeIframeAPIFailedToLoad.postMessage('')"></script>
            <script>
                var player;
                var time;
                YT.ready(function() {
                         player = new YT.Player('player', %@);
                         webkit.messageHandlers.onYouTubeIframeAPIReady.postMessage('');
                         function updateTime() {
                             var state = player.getPlayerState();
                             if (state == YT.PlayerState.PLAYING) {
                                time = player.getCurrentTime();
                                webkit.messageHandlers.onUpdateCurrentTime.postMessage(time);
                             }
                         }
                         window.setInterval(updateTime, 500);
                         });
                         function onReady(event) {
                             webkit.messageHandlers.onReady.postMessage('');
                         }
            function onStateChange(event) {
                webkit.messageHandlers.onStateChange.postMessage(event.data);
            }
            function onPlaybackQualityChange(event) {
                webkit.messageHandlers.onPlaybackQualityChange.postMessage(event.data);
            }
            function onPlaybackRateChange(event) {
                webkit.messageHandlers.onPlaybackRateChange.postMessage(event.data);
            }
            function onPlayerError(event) {
                webkit.messageHandlers.onError.postMessage(event.data);
            }
            function onApiChange(event) {
                webkit.messageHandlers.onApiChange.postMessage(event.data);
            }
            </script>
        </body>
        </html>
        """
        
        self.player.loadPlayerHTML(htmlString!)

comment this code: //self.player.loadPlayer()

Now it should work!!!

tuvia avatar Jul 03 '22 23:07 tuvia

Hi! I ended up wrapping the changes in a new plugin, based on this one. I did this because when you build you app using Codemagic, for example, it retrieves the non modified files and keeps causing problems.

The plugin's name is flutter_youtube_view_plus https://pub.dev/packages/flutter_youtube_view_plus

It has only two modifications:

  1. Solves the bundle problem (cause of the crash)
  2. Adds a parameter to the video player to remove the YouTube link (modestbranding)

Enjoy!

tuvia avatar Jul 11 '22 12:07 tuvia

Hi! I ended up wrapping the changes in a new plugin, based on this one. I did this because when you build you app using Codemagic, for example, it retrieves the non modified files and keeps causing problems.

The plugin's name is flutter_youtube_view_plus https://pub.dev/packages/flutter_youtube_view_plus

It has only two modifications:

  1. Solves the bundle problem (cause of the crash)
  2. Adds a parameter to the video player to remove the YouTube link (modestbranding)

Enjoy!

it solved my crash problem thanks

gulmensedat avatar Aug 11 '22 05:08 gulmensedat

Thank you @tuvia, I can confirm that your fork works fine, but why create a new package and don't create a pull request. Is there a reason for that?

davidgalarza avatar Aug 26 '22 18:08 davidgalarza

Hi! Thank you for your comment. I just needed a quick and fast fox for a production app... That's the only reason.

tuvia avatar Aug 26 '22 18:08 tuvia