Skip to content

Commit 0062907

Browse files
committed
处理逻辑完善
1 parent 2f9c2f2 commit 0062907

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

etc/branchie.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22
[video]
3-
videoDirectory = "D:/workspace/lincang-yizhong/branchy-videos"
3+
videoDirectory = "D:/tmp/branchie-video"

src/app/core/models/branchie-video-fsm.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export class BranchieVideoFsm {
1717

1818
constructor(videoConfig: BranchieVideoConfig, private readonly eventsSink: BranchieVideoFsmEventsSink) {
1919
this.startupActivityInternal = videoConfig.activities.filter(x => x.isStart)[0];
20-
this.endActivityInternal = videoConfig.activities.filter(x => x.isEnd)[0];
2120

2221
this.fsm = new StateMachine<string, string>({
2322
accessor: () => this.currentActivityID, mutator: state => this.currentActivityID = state
@@ -48,10 +47,6 @@ export class BranchieVideoFsm {
4847
return this.startupActivityInternal;
4948
}
5049

51-
get endActivity(): BranchieVideoActivity {
52-
return this.endActivityInternal;
53-
}
54-
5550
get totalScore(): number {
5651
return this.totalScoreNow;
5752
}
@@ -85,6 +80,9 @@ export class BranchieVideoFsm {
8580
this.totalScoreNow += to.score; // 计分
8681
//this.OnActivityEntryEvent?.Invoke(this, new OnActivityEntryEventArgs(from, to, trigger));
8782
await this.eventsSink.onEnterActivity(trigger);
83+
if(to.isEnd) {
84+
this.totalScoreNow = 0;
85+
}
8886
}
8987

9088
}

src/app/home/home.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export class HomeComponent implements OnInit, BranchieVideoFsmEventsSink{
4242
console.log('触发器 tid=' + trigger.id);
4343

4444
const act = this.videoFsm.currentActivity;
45+
if(this.videoUrl !== act.video) {
46+
this.videoUrl = act.video;
47+
}
48+
4549
this.rewind(act.timeStart); // activity 里的时间是毫秒,播放器需要秒
4650
this.resume();
4751
}
@@ -55,6 +59,7 @@ export class HomeComponent implements OnInit, BranchieVideoFsmEventsSink{
5559
}
5660

5761
onVideoDurationChanged(event): void {
62+
console.log(this.videoUrl.toString());
5863
/*
5964
if (!isNaN(this.videoDuration)) {
6065
this.videoDuration = this.player.nativeElement.duration * 1000;
@@ -108,6 +113,7 @@ export class HomeComponent implements OnInit, BranchieVideoFsmEventsSink{
108113
}
109114

110115
private async reinit(): Promise<void> {
116+
this.clearTransitions();
111117
const videoConfig = await this.videoService.loadVideoConfig();
112118
this.videoFsm = new BranchieVideoFsm(videoConfig, this);
113119
this.playVideo();
@@ -174,7 +180,10 @@ export class HomeComponent implements OnInit, BranchieVideoFsmEventsSink{
174180
private updateTime(): void {
175181
const act = this.videoFsm.currentActivity;
176182
this.videoTime = (this.player.nativeElement.currentTime * 1000.0) - act.timeStart;
177-
this.videoDuration = act.timeEnd - act.timeStart;
183+
let endTime = (act.timeEnd !== undefined && !isNaN(act.timeEnd) ?
184+
act.timeEnd : this.player.nativeElement.duration * 1000);
185+
endTime = isNaN(endTime) ? 0 : endTime;
186+
this.videoDuration = endTime - act.timeStart;
178187
}
179188

180189
}

0 commit comments

Comments
 (0)