-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🆕 feat(labs): add xgplayer component (#1685)
- Loading branch information
Showing
38 changed files
with
1,291 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@using Masa.Blazor.Components.Xgplayer.Plugins.Controls | ||
|
||
<MXgplayer Class="mx-auto" | ||
Url="@("https://img-cdn.lonsid.cn/download/1703002472.mp4")"> | ||
<MXgplayerControls Mode="ControlsMode.Flex"></MXgplayerControls> | ||
</MXgplayer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<MXgplayer Class="mx-auto" | ||
Url="@("https://img-cdn.lonsid.cn/download/1703002472.mp4")"> | ||
</MXgplayer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@using Masa.Blazor.Components.Xgplayer.Plugins | ||
|
||
<MXgplayer Class="mx-auto" | ||
Url="@("https://img-cdn.lonsid.cn/download/1703002472.mp4")" | ||
Ignores="new[] { BuiltInPlugin.CssFullscreen }"> | ||
</MXgplayer> |
9 changes: 9 additions & 0 deletions
9
docs/Masa.Blazor.Docs/Examples/labs/xgplayer/MusicPlayer.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@using Masa.Blazor.Components.Xgplayer.Plugins.Controls | ||
|
||
<MXgMusicPlayer Width="@("100%")" | ||
Height="50" | ||
Url="@("https://cdn.masastack.com/stack/doc/blazor/components/xgplayer/Happy%20Whistling%20Ukulele.mp3")"> | ||
<MXgplayerControls InitShow | ||
AutoHide="false" | ||
Mode="ControlsMode.Flex" /> | ||
</MXgMusicPlayer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<MXgplayer Class="mx-auto" | ||
Url="@("https://img-cdn.lonsid.cn/download/1703002472.mp4")" | ||
StartTime="30"> | ||
</MXgplayer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
@using Masa.Blazor.Components.Xgplayer.Plugins | ||
@using Masa.Blazor.Components.Xgplayer | ||
|
||
<div style="width: 100%" class="text-center"> | ||
<div style="width: 600px;height: 338px; background-color: #000000" | ||
class="mx-auto"> | ||
@if (_isMusic) | ||
{ | ||
<MXgMusicPlayer Url="@("https://cdn.masastack.com/stack/doc/blazor/components/xgplayer/1703002472.m4a")" | ||
Autoplay="@_isRunning" | ||
Width="@("100%")" | ||
Height="@("100%")" | ||
StartTime="@_startTime" | ||
Ignores="new[] { BuiltInPlugin.MusicBackward, BuiltInPlugin.MusicForward, BuiltInPlugin.MusicNext, BuiltInPlugin.MusicPrev }" | ||
@ref="_xgMusicPlayer"> | ||
<MXgplayerControls AutoHide="false" InitShow></MXgplayerControls> | ||
<MXgplayerPlay Index="0"></MXgplayerPlay> | ||
</MXgMusicPlayer> | ||
} | ||
else | ||
{ | ||
<MXgplayer Url="@("https://img-cdn.lonsid.cn/download/1703002472.mp4")" | ||
Autoplay="@_isRunning" | ||
Width="@("100%")" | ||
Height="@("100%")" | ||
StartTime="_startTime" | ||
@ref="@_xgplayer"> | ||
<MXgplayerControls InitShow AutoHide="false" /> | ||
</MXgplayer> | ||
} | ||
</div> | ||
|
||
<MButton Class="mt-1" Color="primary" OnClick="@ToggleMusic">Toggle to @(_isMusic ? "Video" : "Music")</MButton> | ||
</div> | ||
|
||
@code { | ||
|
||
private bool _isMusic; | ||
|
||
private double _startTime; | ||
private bool _isRunning; | ||
|
||
private MXgMusicPlayer _xgMusicPlayer = null!; | ||
private MXgplayer _xgplayer = null!; | ||
|
||
private async Task ToggleMusic() | ||
{ | ||
if (_isMusic) | ||
{ | ||
_isMusic = false; | ||
await SetStateAsync(_xgMusicPlayer); | ||
} | ||
else | ||
{ | ||
_isMusic = true; | ||
await SetStateAsync(_xgplayer); | ||
} | ||
} | ||
|
||
private async Task SetStateAsync(MXgMusicPlayer player) | ||
{ | ||
var attr = await player.GetPropsAndStatesAsync(); | ||
_startTime = attr.CurrentTime; | ||
_isRunning = attr.State == XgplayerState.Running; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
docs/Masa.Blazor.Docs/wwwroot/pages/labs/xgplayer/en-US.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: Xgplayer | ||
desc: "A HTML5 video player component base on [Xigua Video Playerv3.0.11](https://h5player.bytedance.com/en)." | ||
tag: "JS Proxy" | ||
--- | ||
|
||
You need to reference the following files before using it: | ||
|
||
```html | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.css"/> | ||
``` | ||
|
||
## Usage | ||
|
||
<masa-example file="Examples.labs.xgplayer.Default"></masa-example> | ||
|
||
<app-alert type="warning" content="The `Url` parameter is the only one that can be updated in real time. Other parameters only take effect when initialized."></app-alert> | ||
|
||
## Examples | ||
|
||
### Props | ||
|
||
#### StartTime | ||
|
||
`StartTime` property can specify the start time of the video. | ||
|
||
<masa-example file="Examples.labs.xgplayer.StartTime"></masa-example> | ||
|
||
#### Ignores | ||
|
||
Disable plugins through the `Ignores` property. The built-in plugin list can be viewed in `BultinPlugins`. | ||
|
||
<masa-example file="Examples.labs.xgplayer.Ignores"></masa-example> | ||
|
||
### Misc | ||
|
||
#### Switch music and video | ||
|
||
**MXgMusicPlayer** is a separate music player component. | ||
This example shows how to switch between music and video. | ||
The `_startTime` field is used to record the progress of video and audio playback. | ||
The `_isRunning` field is used to record whether the video or audio is playing. | ||
|
||
<masa-example file="Examples.labs.xgplayer.Switch"></masa-example> | ||
|
||
## Music player | ||
|
||
**MXgplayer** has a base class component **MXgMusicPlayer** that can be used separately. | ||
|
||
<masa-example file="Examples.labs.xgplayer.MusicPlayer"></masa-example> | ||
|
||
## Plugin components | ||
|
||
Currently, only three plugin components **Controls**, **Play**, **Time** are implemented, | ||
and other plugin components are welcome to PR. | ||
|
||
### Controls | ||
|
||
Use the built-in control plugin component to customize the style of the control bar. | ||
|
||
<masa-example file="Examples.labs.xgplayer.Controls"></masa-example> |
58 changes: 58 additions & 0 deletions
58
docs/Masa.Blazor.Docs/wwwroot/pages/labs/xgplayer/zh-CN.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
title: Xgplayer(西瓜视频播放器) | ||
desc: "一个基于 [Xigua Video Playervv3.0.11](https://h5player.bytedance.com/) 的 HTML5 视频播放器组件。" | ||
tag: "JS代理" | ||
--- | ||
|
||
在使用之前你必须引入以下文件: | ||
|
||
```html | ||
<link rel="stylesheet" href="https://cdn.masastack.com/npm/xgplayer/3.0.11/xgplayer.min.css"/> | ||
``` | ||
|
||
## 使用 | ||
|
||
<masa-example file="Examples.labs.xgplayer.Default"></masa-example> | ||
|
||
<app-alert type="warning" content="仅支持`Url`参数实时更新,其他参数只有初始化时才会生效。"></app-alert> | ||
|
||
## 示例 | ||
|
||
### 属性 | ||
|
||
#### 开始时间 | ||
|
||
`StartTime` 属性可以指定视频的开始播放时间。 | ||
|
||
<masa-example file="Examples.labs.xgplayer.StartTime"></masa-example> | ||
|
||
#### 禁用插件 | ||
|
||
通过 `Ignores` 属性禁用插件,内置的插件列表在 `BultinPlugins` 中可以查看。 | ||
|
||
<masa-example file="Examples.labs.xgplayer.Ignores"></masa-example> | ||
|
||
### 其他 | ||
|
||
#### 切换音乐和视频 | ||
|
||
**MXgMusicPlayer** 是单独的音乐播放器组件,这个例子演示了如何在音乐和视频之间切换。 | ||
`_startTime` 字段用于记录视频和音频播放的进度。`_isRunning` 字段用于记录视频或音频是否正在播放。 | ||
|
||
<masa-example file="Examples.labs.xgplayer.Switch"></masa-example> | ||
|
||
## 音乐播放器 | ||
|
||
**MXgplayer** 结构上有个 **MXgMusicPlayer** 的基类组件,可以单独使用。 | ||
|
||
<masa-example file="Examples.labs.xgplayer.MusicPlayer"></masa-example> | ||
|
||
## 插件组件 | ||
|
||
目前仅实现了 **Controls**、**Play**、**Time** 三个插件组件,其他插件组件欢迎 PR。 | ||
|
||
### 控制条 | ||
|
||
使用内置的控制插件组件,可以自定义控制条的样式。 | ||
|
||
<masa-example file="Examples.labs.xgplayer.Controls"></masa-example> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Masa.Blazor.Components.Xgplayer; | ||
|
||
public interface IXgplayer | ||
{ | ||
Task ConfigPluginAsync(object plugin); | ||
} |
Oops, something went wrong.