inbasic / media-player

A simple yet powerful media player for browser built on top of video.js
https://webextension.org/listing/the-media-player.html
36 stars 27 forks source link

[Feature Request] Chromecast Button #31

Open Xeais opened 2 years ago

Xeais commented 2 years ago

First, this is a good media player - well done.

As the title already states, could you add a button to the control bar which will cast videos to a Chromecast? That would be a nice little addition.

There is already a plugin for this here at GitHub.

Thank you for your efforts - best regards

inbasic commented 2 years ago

There is already a right-click context menu over the player for casting (a native feature of the video element). As far as I can tell, this plug-in does not work with the latest VideoJS. Also, I believe if you load the player in a tab, Chrome displays the native cast icon in the toolbar area.

Xeais commented 2 years ago

While the right-click menu is a little bit more convenient than the "File"-detour, it triggers the exact same Chromium casting menu. This always leads to a playback error at the beginning of each video: 1:1 playback then ensures the video is played nevertheless; however, as a result, the video will now play from the TV and the laptop together, leaving the laptop display on. This is mildly distracting, yet no big deal. The thing is that the problem does not arise when casting a video from a player's Chromecast button itself (such as found on YouTube, for example). By the way, I am not using Chrome, but a Chromium competitor, Vivaldi (currently 5.2.2623.48) to be precise. There is no way to display a native toolbar cast icon with Vivaldi (and arguably other Chromium web browsers as well - apart from Chrome itself).

I have not used this plugin myself but they claim it should work with Video.js 6+ and the last main code commit is only three months old (Video.js 7.18.1 was current then - rather a small difference compared to the current version 7.19 .2).

inbasic commented 2 years ago

I finally got this to work by redirecting remote scripts to the local ones. Anyhow give the latest commit a try and let me know if it works for you or not. Currently, the extension uses the default configs.

https://github.com/inbasic/media-player/blob/master/v3/data/player/video.js/plugins/cast/video.js-cast.js#L57-L60

Let me know if you need instructions on how to load a temporary extension.

Xeais commented 2 years ago

You, my friend, are great!

Unfortunately, version 3's manifest.json got a new line minimum_chrome_version": "102" which successfully prevents loading with the latest Vivaldi (5.2.2623.48 (Stable channel) (64-Bit)). 😁

inbasic commented 2 years ago

Remove the "minimum_chrome_version" line from manifest.json and retry. Might get an error, but the player appears.

Xeais commented 2 years ago

I didn't want to just remove that line on my own. After removal, the installation was successful. I got one warning and ten errors - nothing blocked. Consequently, the player loads with a Cast button ("Cast Video"). So far so good, but now, only desktop casting still works. Standard configurations don't seem to play along ...

MediaPlayer-Errors

inbasic commented 2 years ago

Since your browser does not support optional host permission, the link grabber is not working for you. The last commit fixes a few bugs in the log.

Xeais commented 2 years ago

Vivaldi is using Chromium version 100.0.4896.162 for now, but this is updated regularly and optional_host_permissions for manifest.json should come with Chromium version 101 or 102, so this issue should just go away with time (by the way, this was the one warning not included in the image above).

Addendum

  1. Microsoft Edge is now running Chromium version 102.0.5005.63 (Vivaldi with version 102.0.5005.72 is also affected) and unfortunately, casting (the trigger doesn't matter) doesn't work there either; for this reason, I am still using the second version. By the way, version three can be installed in both web browsers without any warnings or errors.
  2. The player is currently not playing any sound in Vivaldi. Update: Version 3 and version 0.4.2 of MediaPlayer no longer exhibit this problem with Vivaldi (version 5.3.2679.51, stable channel, 64-bit).
  3. Something nice to conclude: Even though browser support of High Efficiency Video Coding (HEVC) or H.265 is lacking, Video.js seems to play some videos encoded that way. Update: It seems that most, if not all, HEVC-videos play just fine, but this applies only to Microsoft Edge (tested with version 102.0.1245.39, official build, 64-bit).

Thank you for the bug fixes!

inbasic commented 2 years ago

Video.js seems to play some videos encoded that way.

Do you have a sample?

unfortunately, casting (the trigger doesn't matter) doesn't work there either

Anything useful on the console?

Xeais commented 2 years ago

A MKV-file with the following specifications is played perfectly fine as extension of Microsoft Edge (version 102.0.1245.33, official build, 64-bit | with Vivaldi version 5.3.2679.38, stable channel, 64-bit I get: "The media could not be loaded, either because the server or network failed or because the format is not supported." | via MediaInfo V22.03 - changed and abridged):

The update to the third bullet point of the addendum renders this first part almost entirely obsolete.

General

Format: Matroska Format Version: Version 4 File Size: 1.02 GiB Overall Bit Rate: 2 483 kb/s Encoded Application: mkvmerge v41.0.0 ('Smarra') 64-bit Encoded Library: libebml v1.3.9 + libmatroska v1.5.2 / Lavf58.76.100

Video

ID: 1 Format: HEVC Format: High Efficiency Video Coding Format: Main 10@L4@Main Codec ID: V_MPEGH/ISO/HEVC Bit Rate: 2 225 kb/s Width: 1 920 pixels Height: 1 080 pixels Display Aspect Ratio: 16:9 Frame Rate Mode: Variable Frame Rate: 23.976 FPS Color Space: YUV Chroma Subsampling: 4:2:0 Bit Depth: 10 bits Bits-(Pixel*Frame): 0.045 Stream Size: 937 MiB (90%) Language: English Default: Yes Forced/String: No Colour Range: Full Colour Range Original: Limited Colour Primaries: BT.709 Transfer Characteristics: BT.709 Matrix Coefficients: BT.709

Audio

ID: 2 Format: AC-3 Format/Info: Audio Coding 3 Format Commercial If Any: Dolby Digital Codec ID: A_AC3 Duration: 58 min 52 s Bit Rate Mode: Constant Bit Rate: 256 kb/s Channel(s): 6 channels Channel Layout: L R C LFE Ls Rs Sampling Rate: 48.0 kHz Frame Rate: 31.250 FPS (1536 SPF) Compression Mode: Lossy Stream Size: 108 MiB (10%) Encoded Library: Lavc58.134.100 ac3 Language: English Service Kind: Complete Main Default: Yes Forced: No


Sometimes when the player starts, the error "ResizeObserver loop limit exceeded" (caused by the video.js-file) is issued twice.

Microsoft Edge's DevTools then (after loading a video file, trying to cast it (failure) and pressing the stop-button) report: Microsoft Edge MediaPlayer Errors and Warnings

This is all there is!

Xeais commented 2 years ago

With version 0.4.4 of MediaPlayer the cast button is only shown in Firefox (by the way, regarding your Firefox detection const isFF = /Firefox/.test(navigator.userAgent); - there are Firefox forks like LibreWolf); may I ask for the reason?

The good thing though: I believe this is the first 0.4.X version in which casting, via context menu, actually works.

inbasic commented 2 years ago

cast button is only shown in Firefox

The code intends to hide the case button on Firefox: https://github.com/inbasic/media-player/blob/master/v3/worker.js#L285

On Chromium, right-click the action button and enable the plugin if you need it. Since this plugin does remote pings, it is now opt-in.

there are Firefox forks like LibreWolf

I am not familiar with this browser. However, most likely, all the forks have "Firefox" in their user-agent string.

Xeais commented 2 years ago

Remember: Never just glance at foreign source code! 😅 I was also led to the wrong conclusion by the fact that the plugin did not appear in the Chromium-based Microsoft Edge; although the deactivation was not done in the source code there. It's now activated, thanks for the tip. Unfortunately, casting via plugin still doesn't work. It just shows the cast button icon in the center of the TV screen without any additional output in Microsoft Edge's DevTools after ending a failed attempt.

In case of LibreWolf, you are right: I just checked my test installation which yielded "Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0". I just wanted to point out that there are (good) Firefox forks that might complicate web browser detection.