Skip to content

Commit 545de88

Browse files
authored
fix(VideoFeeder): should not be muted on play when AutoPlay is false (#2560)
* fix🐛 (VideoFeeder): should not be muted on play when AutoPlay is false * 🐛 fix(Xgplayer): Cannot read properties of undefined(reading 'destroy')
1 parent 91dfb55 commit 545de88

File tree

8 files changed

+29
-10
lines changed

8 files changed

+29
-10
lines changed

src/Masa.Blazor.JS/src/wrappers/xgplayer/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Xgplayer, { Events, IPlayerOptions, Start } from "xgplayer";
22
import MusicPreset, { Music } from "xgplayer-music";
3+
import DynamicBg from "xgplayer/es/plugins/dynamicBg";
34
import Mobile from "xgplayer/es/plugins/mobile";
45
import Play from "xgplayer/es/plugins/play";
56
import Playbackrate from "xgplayer/es/plugins/playbackRate";
67
import Progress from "xgplayer/es/plugins/progress";
78
import Time from "xgplayer/es/plugins/time";
89
import Volume from "xgplayer/es/plugins/volume";
9-
import DynamicBg from "xgplayer/es/plugins/dynamicBg";
1010

1111
export type XgplayerOptions = Omit<
1212
IPlayerOptions,
@@ -339,11 +339,18 @@ class XgplayerProxy {
339339
};
340340

341341
destroy() {
342-
this.el &&
342+
if (this.el) {
343343
this.el.removeEventListener("touchend", this.onFullscreenTouchend);
344-
this.player.destroy();
345-
this.player = null;
346-
this.handle.dispose();
344+
}
345+
346+
if (this.player) {
347+
this.player.destroy();
348+
this.player = null;
349+
}
350+
351+
if (this.handle) {
352+
this.handle.dispose();
353+
}
347354
}
348355

349356
private debug(message: string, ...args: any[]) {

src/Masa.Blazor.JSComponents.VideoFeeder/VideoFeeder/MVideoFeeder.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
GlobalMuted="@_globalMuted"
3030
GlobalMutedChanged="@OnGlobalMutedChange"
3131
Autoplay="@Autoplay"
32+
AutoplayMuted="@AutoplayMuted"
3233
Loop="@_autoplayNext"
3334
DynamicBg="@DynamicBg"
3435
RotateFullscreen="@RotateFullscreen"

src/Masa.Blazor.JSComponents.VideoFeeder/VideoFeeder/MVideoFeeder.razor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public partial class MVideoFeeder<TItem> where TItem : notnull
2525

2626
[Parameter] public bool Autoplay { get; set; }
2727

28+
[Parameter] public bool AutoplayMuted { get; set; }
29+
2830
[Parameter] public bool DynamicBg { get; set; }
2931

3032
/// <summary>
@@ -93,6 +95,7 @@ protected override void OnInitialized()
9395
base.OnInitialized();
9496

9597
_autoplayNext = DefaultAutoplayNext;
98+
_globalMuted = AutoplayMuted;
9699
UpdateVideos();
97100
}
98101

@@ -111,7 +114,7 @@ private void UpdateVideos()
111114
if (!_itemsHasSet && Items.Count > 0)
112115
{
113116
_itemsHasSet = true;
114-
_videos = Items.Select(i => new Video<TItem>(i, ItemUrl, ItemPoster, ItemStartTime)).ToList();
117+
_videos = Items.Select(i => new Video<TItem>(i, ItemUrl, ItemPoster, ItemStartTime, AutoplayMuted)).ToList();
115118
}
116119
}
117120

src/Masa.Blazor.JSComponents.VideoFeeder/VideoFeeder/Player.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<MXgplayer Poster="@poster"
1212
Autoplay="@Autoplay"
13-
AutoplayMuted
13+
AutoplayMuted="@AutoplayMuted"
1414
StartTime="@Data.StartTime"
1515
Loop="@Loop"
1616
Url="@Data.Url"

src/Masa.Blazor.JSComponents.VideoFeeder/VideoFeeder/Player.razor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public partial class Player<TItem> : MasaComponentBase where TItem : notnull
1616

1717
[Parameter] public bool Autoplay { get; set; }
1818

19+
[Parameter] public bool AutoplayMuted { get; set; }
20+
1921
[Parameter] public int Index { get; set; }
2022

2123
[Parameter] public bool GlobalMuted { get; set; }

src/Masa.Blazor.JSComponents.VideoFeeder/VideoFeeder/Video.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ namespace Masa.Blazor.JSComponents.VideoFeeder;
44

55
public class Video<TItem> where TItem : notnull
66
{
7-
internal Video(TItem item, Func<TItem, string?> url, Func<TItem, string?>? poster, Func<TItem, double>? startTime)
7+
internal Video(
8+
TItem item,
9+
Func<TItem, string?> url,
10+
Func<TItem, string?>? poster,
11+
Func<TItem, double>? startTime,
12+
bool muted)
813
{
914
Poster = poster?.Invoke(item);
1015
Url = url.Invoke(item);
1116
StartTime = startTime?.Invoke(item) ?? 0;
17+
Muted = muted;
1218
Item = item;
1319
}
1420

src/Masa.Blazor.JSComponents.Xgplayer/wwwroot/xgplayer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Masa.Blazor.JSComponents.Xgplayer/wwwroot/xgplayer.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)