DetailPlayShortVideoPage.ets
5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import router from '@ohos.router';
import mediaquery from '@ohos.mediaquery';
import window from '@ohos.window';
import { Action } from 'wdBean';
import { WindowModel, SPHelper, Logger } from 'wdKit';
import { WDPlayerController, WDPlayerRenderView, PlayerConstants } from 'wdPlayer';
import { devicePLSensorManager } from 'wdDetailPlayApi';
import { PlayControlViewContainer } from '../view/PlayControlViewContainer';
import { PlayerDetailContainer } from '../view/PlayerDetailContainer';
import { PlayViewModel } from '../viewmodel/PlayViewModel';
import { DetailContainer } from '../view/DetailContainer';
const TAG = 'DetailPlayShortVideoPage';
/**
* 详情&短视频播放页面
*/
@Entry
@Component
export struct DetailPlayShortVideoPage {
private contentId?: string = undefined
private relId?: string = undefined
private relType?: string = undefined
private playerController: WDPlayerController = new WDPlayerController();
@Watch("urlChanged") @State url?: string = undefined
@Watch('changeContinue') @Provide nextContId?: string = '';
@Watch('getPlayHistory') @Provide curContId?: string = undefined;
@Watch("playVMChanged") @Provide playVM: PlayViewModel = new PlayViewModel();
@Provide isFullScreen: boolean = false;
@Provide canStart?: boolean = false;
@Provide status: number = PlayerConstants.STATUS_START;
@Provide userId: string = '';
@Provide newsSourceName?: string = undefined
@Provide title?: string = undefined
@Provide message?: string = undefined
@Provide newsSummary?: string = undefined
@Provide progressVal: number = 0;
playVMChanged(name: string) {
this.url = this.playVM.url
this.newsSourceName = this.playVM.newsSourceName
this.title = this.playVM.title
this.curContId = this.playVM.contentId
this.nextContId = this.playVM.nextContId
this.canStart = this.playVM.canStart;
this.message = this.playVM.message
this.newsSummary = this.playVM.newsSummary
}
aboutToAppear() {
let action: Action = router.getParams() as Action
if (action) {
this.contentId = action.params?.contentID
if (action.params && action.params.extra) {
this.relId = action.params.extra.relId
this.relType = action.params.extra.relType
}
}
// 设置播放地址
// this.url = 'https://media.w3.org/2010/05/sintel/trailer.mp4'
let listener = mediaquery.matchMediaSync('(orientation: landscape)');
listener.on("change", (mediaQueryResult) => {
if (mediaQueryResult.matches) {
console.log("横屏 yes")
this.isFullScreen = true
} else {
this.isFullScreen = false
console.log("横屏 no")
}
WindowModel.shared.setMainWindowFullScreen(this.isFullScreen)
})
}
onPageShow() {
WindowModel.shared.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED);
}
onPageHide() {
WindowModel.shared.setPreferredOrientation(window.Orientation.PORTRAIT);
devicePLSensorManager.devicePLSensorOff();
this.status = PlayerConstants.STATUS_PAUSE;
this.playerController?.pause();
}
@Builder
playerViewContainer() {
// 播放窗口
WDPlayerRenderView({
playerController: this.playerController,
onLoad: async () => {
// this.playVM.playWithContentId(this.contentId ?? "846899373")
this.playVM.playWithIds(this.contentId ?? "846899373",
this.relId ?? "500000301942", this.relType ?? "1")
}
})
.height('100%')
.width('100%')
}
@Builder
playControlViewContainer() {
// 播放窗口控制bar
PlayControlViewContainer({
playerController: this.playerController
})
}
@Builder
detailContainer() {
// DetailTabBarPageComponent({ pageId: this.pageId }).backgroundColor(Color.Black)
DetailContainer({
playerController: this.playerController
})
}
build() {
Row() {
PlayerDetailContainer({ playerView: () => {
this.playerViewContainer()
}, playControlView: () => {
this.playControlViewContainer()
}, detailView: () => {
this.detailContainer()
} })
.height('100%')
.width('100%')
}
.height('100%')
.width('100%')
.backgroundColor(Color.Black)
}
// 续播判断
changeContinue() {
if (this.nextContId) {
this.playerController.continue = () => {
this.playerController?.stop();
this.playVM.playWithContentId(this.nextContId ?? '');
}
return;
}
this.playerController.continue = undefined;
}
urlChanged(name: string) {
if (this.url) {
console.log("url:" + this.url);
this.status = PlayerConstants.STATUS_START;
this.playerController.firstPlay(this.url);
}
}
getPlayHistory() {
SPHelper.default.get('playHistory', '').then((str) => {
let result = str.toString();
let time = 0;
if (result != null && result != "") {
let playHistory: Record<string, Record<string, number>> = JSON.parse(result);
let userData: Record<string, number> = {};
if (this.userId) {
userData = playHistory[this.userId] ?? {};
}
if (this.curContId) {
time = userData?.[this.curContId] ?? 0;
}
}
this.playerController?.setStartTime(time);
}).catch((err: Error) => {
// Error: Inner error. Error code 15500000
Logger.error(TAG, 'catch err:' + JSON.stringify(err));
this.playerController?.setStartTime(0);
});
}
}