Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(extensions): Youtube Video Player Support Mode #1916

Merged
merged 7 commits into from
Jun 29, 2024

Conversation

EchoEllet
Copy link
Collaborator

@EchoEllet EchoEllet commented Jun 13, 2024

Description

A workaround for loading YouTube videos on a Desktop without Webview.

Loading YouTube videos using WebView Platform View in QuillEditor causes some issues, requires flutter_inappwebview which requires setup on Web, doesn't support Desktop yet

On pub.dev page it is marked as supported on macOS

Screenshot

image

Though it's not supported yet on macOS, see #2004 or #460 for more details.

If you try to use it on macOS platform you will get this exception:

createPlatformInAppWebViewWidget is not implemented on the current platform.

I caught this while testing the previous two PRs sent recently.

A workaround, in my opinion, is a better solution even on other platforms, is to get the download/video URL and load it using a Video player without a platform widget using plugins with Webview.

The only issue is, as far as I remember, YouTube's terms of service don't allow this unless you download the video using the download button or use it using IFrame which is the main reason why YouTube video player packages use Webview, though we could improve this to make UI similar to the provided IFrame (with Youtube link) to make it clear this video is coming from Youtube, and we could disable this feature if the video author doesn't allow using IFrame feature which will give a similar result to using IFrame, however.

I'm still unsure if this is allowed.

This is why I changed this from a bug fix into a feature that providesYoutubeVideoSupportMode option:

/// Enum represents the different modes for handling YouTube video support.
enum YoutubeVideoSupportMode {
  /// Disable loading of YouTube videos.
  disabled,

  /// Load the video using the official YouTube IFrame API.
  /// See [YouTube IFrame API](https://developers.google.com/youtube/iframe_api_reference) for more details.
  ///
  /// This will use Platform View on native platforms to use WebView
  /// The WebView might not be supported on Desktop and will throw an exception
  iframeView,

  /// Load the video using a custom video player by fetching the YouTube video URL.
  /// Note: This might violate YouTube's terms of service.
  /// See [YouTube Terms of Service](https://www.youtube.com/static?template=terms) for more details.
  customPlayerWithDownloadUrl,
}

The default is YoutubeVideoSupportMode.iframeView to avoid breaking behavior.

You can set youtubeVideoSupportMode to load the YouTube video by Download URL on Desktop platforms:

// Loading YouTube videos on Desktop is not supported yet
// when using iframe platform view
// See https://github.com/pichillilorenzo/flutter_inappwebview/issues/460 for details
youtubeVideoSupportMode: isDesktop(supportWeb: false)
    ? YoutubeVideoSupportMode.customPlayerWithDownloadUrl
    : YoutubeVideoSupportMode.iframeView,
),

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the package version in pubspec.yaml files.
  • All existing and new tests are passing.
  • I have run the commands in ./scripts/before_push.sh and it all passed successfully

Breaking Change

Does your PR require developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

@EchoEllet EchoEllet changed the title Fix: Youtube Video Player on Desktop for the extensions package feat(extensions): Youtube Video Player Support Mode Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants