Skip to content

Commit 23dc970

Browse files
committed
[*] refactor: video-editor
1 parent 5da41cd commit 23dc970

File tree

9 files changed

+52
-14
lines changed

9 files changed

+52
-14
lines changed

lib/video-editor/src/preview/renderer.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl PreviewRenderer {
191191
SamplesBuffer::new(channels, sample_rate, audio.samples.clone());
192192
sink.append(source);
193193

194-
if sink.is_paused() {
194+
if sink.is_paused() && self.controller.state() == PlaybackState::Playing {
195195
sink.play();
196196
}
197197
}
@@ -229,6 +229,11 @@ impl PreviewRenderer {
229229
} else {
230230
self.controller.pause();
231231
self.mixer_iter = None;
232+
if let Some(sink) = &self.audio_sink
233+
&& let Ok(sink) = sink.lock()
234+
{
235+
sink.pause();
236+
}
232237
}
233238
}
234239

@@ -245,6 +250,7 @@ impl PreviewRenderer {
245250
})?;
246251

247252
let sink = AudioSink::connect_new(&device_sink.mixer());
253+
sink.set_volume(self.controller.volume());
248254

249255
self.audio_stream = Some(device_sink);
250256
self.audio_sink = Some(Arc::new(Mutex::new(sink)));
@@ -291,6 +297,7 @@ impl PreviewRenderer {
291297
&& let Ok(sink) = sink.lock()
292298
&& sink.is_paused()
293299
{
300+
sink.set_volume(self.controller.volume());
294301
sink.play();
295302
}
296303

@@ -335,6 +342,27 @@ impl PreviewRenderer {
335342
self.db_level_cache_left.clear();
336343
self.db_level_cache_right.clear();
337344
self.advance_frame()?;
345+
346+
// 如果无法获取帧(例如在轨道末尾),尝试向前回退获取前一帧
347+
if self.current_frame.is_none() {
348+
let frame_duration = Duration::from_secs_f64(1.0 / self.config.frame_rate());
349+
for offset in 1..10 {
350+
let fallback_position = position.saturating_sub(frame_duration * offset);
351+
if fallback_position.is_zero() && offset > 1 {
352+
break;
353+
}
354+
355+
self.controller.set_position(fallback_position);
356+
self.mixer_iter = None;
357+
self.advance_frame()?;
358+
359+
if self.current_frame.is_some() {
360+
self.controller.set_position(position); // 成功获取帧后,恢复原始位置
361+
break;
362+
}
363+
}
364+
}
365+
338366
Ok(())
339367
}
340368

@@ -375,7 +403,7 @@ impl PreviewRenderer {
375403
SamplesBuffer::new(channels, sample_rate, audio.samples.clone());
376404
sink.append(source);
377405

378-
if sink.is_paused() {
406+
if sink.is_paused() && self.controller.state() == PlaybackState::Playing {
379407
sink.play();
380408
}
381409
}
@@ -398,6 +426,11 @@ impl PreviewRenderer {
398426
} else {
399427
self.controller.pause();
400428
self.mixer_iter = None;
429+
if let Some(sink) = &self.audio_sink
430+
&& let Ok(sink) = sink.lock()
431+
{
432+
sink.pause();
433+
}
401434
}
402435
}
403436

lib/video-editor/src/tracks/audio_track.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl UnifiedAudioTracksMixerIterator {
163163
"max_cache_duration must be greater than cache_duration".into(),
164164
));
165165
}
166-
if timeline_offset >= end_timeline_offset {
166+
if timeline_offset > end_timeline_offset {
167167
return Err(Error::InvalidConfig(
168168
"timeline_offset must be less than end_timeline_offset".into(),
169169
));

todo.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
## 问题
2-
5. 点击跳转到最后按钮没有刷新预览图片
3-
20. 视频已经暂停了,但是点击时间轴跳转的时候,会播放1秒左右的音频
42

53
## 待验证
64

wayshot/src/logic/popup_action.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,16 @@ pub fn init(ui: &AppWindow) {
136136
let index = user_data.parse::<i32>().unwrap();
137137
global_logic!(ui).invoke_video_editor_export_queue_remove(index);
138138
}
139-
"video-editor-add-empyt-video-track" => {
139+
"video-editor-add-empty-video-track" => {
140140
global_logic!(ui).invoke_video_editor_add_empty_video_track();
141141
}
142-
"video-editor-add-empyt-audio-track" => {
142+
"video-editor-add-empty-audio-track" => {
143143
global_logic!(ui).invoke_video_editor_add_empty_audio_track();
144144
}
145-
"video-editor-add-empyt-subtitle-track" => {
145+
"video-editor-add-empty-subtitle-track" => {
146146
global_logic!(ui).invoke_video_editor_add_empty_subtitle_track();
147147
}
148-
"video-editor-add-empyt-overlay-track" => {
148+
"video-editor-add-empty-overlay-track" => {
149149
global_logic!(ui).invoke_video_editor_add_empty_overlay_track();
150150
}
151151
"video-editor-track-move-up" => {

wayshot/src/logic/video_editor/preview.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ fn video_editor_preview_fast_forward(ui: &AppWindow) {
146146

147147
fn video_editor_preview_toggle(ui: &AppWindow) {
148148
create_renderer_if_none(ui);
149+
let ui_state = global_store!(ui).get_video_editor_ui_state();
150+
let volume = ui_state.preview_volumn.clamp(0.0, 100.0) / 100.0;
149151

150152
let mut renderer_guard = PREVIEW_RENDERER.lock().unwrap();
151153
if let Some(ref mut r) = *renderer_guard {
@@ -157,6 +159,7 @@ fn video_editor_preview_toggle(ui: &AppWindow) {
157159
global_store!(ui).set_video_editor_is_previewing(false);
158160
}
159161
PlaybackState::Stopped | PlaybackState::Paused => {
162+
r.set_volume(volume);
160163
if let Err(e) = r.play() {
161164
crate::toast_warn!(ui, format!("Failed to start playback: {:?}", e));
162165
return;

wayshot/ui/base/icon.slint

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ export global Icons {
324324
out property <image> unsave-light: @image-url("../images/icons/unsave-light.svg");
325325
out property <image> empty-fill: @image-url("../images/icons/empty-fill.svg");
326326
out property <image> empty-light: @image-url("../images/icons/empty-light.svg");
327+
out property <image> skip-next-fill: @image-url("../images/icons/skip-next-fill.svg");
328+
out property <image> skip-previous-fill: @image-url("../images/icons/skip-previous-fill.svg");
327329

328330
out property <image> landing-account: @image-url("../images/landing/landing-account.svg");
329331
out property <image> landing-language-switch: @image-url("../images/landing/landing-language-switch.svg");
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

wayshot/ui/panel/desktop/video-editor/preview.slint

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ component Btns inherits Rectangle {
2222
spacing: Theme.spacing * 4;
2323

2424
IconBtn {
25-
icon: Icons.arrow-left-fill;
26-
icon-size: Theme.icon-size * 0.9;
25+
icon: Icons.skip-previous-fill;
26+
icon-size: Theme.icon-size * 1.3;
2727
tip: Logic.tr("previous");
2828
is-show-tip: true;
2929
clicked => {
@@ -52,16 +52,16 @@ component Btns inherits Rectangle {
5252

5353
IconBtn {
5454
icon: Icons.fast-forward-fill;
55-
tip: Logic.tr("fast forward");
55+
tip: Logic.tr("forward");
5656
is-show-tip: true;
5757
clicked => {
5858
Logic.video-editor-preview-fast-forward();
5959
}
6060
}
6161

6262
IconBtn {
63-
icon: Icons.arrow-right-fill;
64-
icon-size: Theme.icon-size * 0.9;
63+
icon: Icons.skip-next-fill;
64+
icon-size: Theme.icon-size * 1.3;
6565
tip: Logic.tr("next");
6666
is-show-tip: true;
6767
clicked => {

0 commit comments

Comments
 (0)