Skip to content

Commit 466aad6

Browse files
authored
Merge pull request #81 from Stremio/fix/next-video
Fix next video behavior
2 parents d09797d + 37aae36 commit 466aad6

5 files changed

Lines changed: 26 additions & 10 deletions

File tree

src/app/imp.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,13 @@ impl ApplicationImpl for Application {
9494
window,
9595
#[weak]
9696
webview,
97-
move || {
97+
move |reason| {
9898
window.enable_idling();
9999

100-
let message = ipc::create_response(IpcEvent::Mpv(IpcEventMpv::Ended(None)));
100+
let message = ipc::create_response(IpcEvent::Mpv(IpcEventMpv::Ended((
101+
reason.to_string(),
102+
None,
103+
))));
101104
webview.send(&message);
102105
}
103106
));

src/app/ipc/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub enum IpcEventMpv {
99
Command((String, Vec<String>)),
1010
Set((String, Value)),
1111
Change((String, Value)),
12-
Ended(Option<String>),
12+
Ended((String, Option<String>)),
1313
}
1414

1515
#[derive(Deserialize, Debug)]

src/app/ipc/response.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,15 @@ impl TryFrom<IpcEvent> for IpcMessageResponse {
8080
"data": value,
8181
}])),
8282
}),
83-
IpcEvent::Mpv(IpcEventMpv::Ended(error)) => Ok(IpcMessageResponse {
83+
IpcEvent::Mpv(IpcEventMpv::Ended((reason, error))) => Ok(IpcMessageResponse {
8484
id: 1,
8585
r#type: 1,
8686
object: TRANSPORT_NAME.to_owned(),
8787
data: None,
8888
args: Some(json!([
8989
"mpv-event-ended",
9090
{
91+
"reason": reason,
9192
"error": error,
9293
}
9394
])),

src/app/video/imp.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use gtk::{
88
use libmpv2::{
99
Format, Mpv, SetData,
1010
events::{Event, PropertyData},
11+
mpv_end_file_reason,
1112
render::{OpenGLInitParams, RenderContext, RenderParam, RenderParamApiType},
1213
};
1314
use std::{cell::RefCell, env, os::raw::c_void, sync::OnceLock};
@@ -97,7 +98,9 @@ impl ObjectImpl for Video {
9798
.param_types([str::static_type(), Variant::static_type()])
9899
.build(),
99100
Signal::builder("playback-started").build(),
100-
Signal::builder("playback-ended").build(),
101+
Signal::builder("playback-ended")
102+
.param_types([str::static_type()])
103+
.build(),
101104
]
102105
})
103106
}
@@ -129,8 +132,17 @@ impl ObjectImpl for Video {
129132
Event::StartFile => {
130133
object.emit_by_name::<()>("playback-started", &[]);
131134
}
132-
Event::EndFile(_) => {
133-
object.emit_by_name::<()>("playback-ended", &[]);
135+
Event::EndFile(reason) => {
136+
let reason = match reason {
137+
mpv_end_file_reason::Eof => "eof".to_string(),
138+
mpv_end_file_reason::Stop => "stop".to_string(),
139+
mpv_end_file_reason::Redirect => "redirect".to_string(),
140+
mpv_end_file_reason::Error => "error".to_string(),
141+
mpv_end_file_reason::Quit => "quit".to_string(),
142+
_ => "other".to_string(),
143+
};
144+
145+
object.emit_by_name::<()>("playback-ended", &[&reason]);
134146
}
135147
_ => {}
136148
});

src/app/video/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ impl Video {
6767
);
6868
}
6969

70-
pub fn connect_playback_ended<T: Fn() + 'static>(&self, callback: T) {
70+
pub fn connect_playback_ended<T: Fn(&str) + 'static>(&self, callback: T) {
7171
self.connect_closure(
7272
"playback-ended",
7373
false,
74-
closure_local!(move |_: Video| {
75-
callback();
74+
closure_local!(move |_: Video, reason: &str| {
75+
callback(reason);
7676
}),
7777
);
7878
}

0 commit comments

Comments
 (0)