implementing PlayNext media
This commit is contained in:
parent
9d5654cd8e
commit
74fa8baa55
3 changed files with 68 additions and 15 deletions
|
|
@ -81,7 +81,7 @@ pub fn parse() -> Arguments {
|
||||||
if urls.len() > 1 {
|
if urls.len() > 1 {
|
||||||
arguments.urls = Some(urls);
|
arguments.urls = Some(urls);
|
||||||
} else {
|
} else {
|
||||||
urls.truncate(1);
|
urls.truncate(1); //does nothing because urls is of len 0 or 1 in this case.
|
||||||
arguments.url_opt = urls.pop();
|
arguments.url_opt = urls.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
75
src/main.rs
75
src/main.rs
|
|
@ -2,25 +2,23 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
Application, ApplicationExt, Element,
|
app::{command, message, Command, Core, Settings},
|
||||||
app::{Command, Core, Settings, command, message},
|
|
||||||
cosmic_config::{self, CosmicConfigEntry},
|
cosmic_config::{self, CosmicConfigEntry},
|
||||||
cosmic_theme, executor, font,
|
cosmic_theme, executor, font,
|
||||||
iced::{
|
iced::{
|
||||||
Alignment, Background, Border, Color, ContentFit, Length, Limits,
|
|
||||||
event::{self, Event},
|
event::{self, Event},
|
||||||
keyboard::{Event as KeyEvent, Key, Modifiers},
|
keyboard::{Event as KeyEvent, Key, Modifiers},
|
||||||
mouse::{Event as MouseEvent, ScrollDelta},
|
mouse::{Event as MouseEvent, ScrollDelta},
|
||||||
subscription::Subscription,
|
subscription::Subscription,
|
||||||
window,
|
window, Alignment, Background, Border, Color, ContentFit, Length, Limits,
|
||||||
},
|
},
|
||||||
iced_style, theme,
|
iced_style, theme,
|
||||||
widget::{self, Slider, menu::action::MenuAction, nav_bar, segmented_button},
|
widget::{self, menu::action::MenuAction, nav_bar, segmented_button, Slider},
|
||||||
|
Application, ApplicationExt, Element,
|
||||||
};
|
};
|
||||||
use iced_video_player::{
|
use iced_video_player::{
|
||||||
Video, VideoPlayer,
|
|
||||||
gst::{self, prelude::*},
|
gst::{self, prelude::*},
|
||||||
gst_pbutils,
|
gst_pbutils, Video, VideoPlayer,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
any::TypeId,
|
any::TypeId,
|
||||||
|
|
@ -34,8 +32,8 @@ use std::{
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{CONFIG_VERSION, Config, ConfigState},
|
config::{Config, ConfigState, CONFIG_VERSION},
|
||||||
key_bind::{KeyBind, key_binds},
|
key_bind::{key_binds, KeyBind},
|
||||||
project::ProjectNode,
|
project::ProjectNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -284,6 +282,7 @@ pub enum Message {
|
||||||
Seek(f64),
|
Seek(f64),
|
||||||
SeekRelative(f64),
|
SeekRelative(f64),
|
||||||
SeekRelease,
|
SeekRelease,
|
||||||
|
PlayNext,
|
||||||
EndOfStream,
|
EndOfStream,
|
||||||
MissingPlugin(gst::Message),
|
MissingPlugin(gst::Message),
|
||||||
MprisChannel(MprisMeta, MprisState, mpsc::UnboundedSender<MprisEvent>),
|
MprisChannel(MprisMeta, MprisState, mpsc::UnboundedSender<MprisEvent>),
|
||||||
|
|
@ -897,7 +896,8 @@ impl Application for App {
|
||||||
let command = match (app.flags.urls.take(), maybe_path) {
|
let command = match (app.flags.urls.take(), maybe_path) {
|
||||||
(Some(urls), _) => command::message::app(Message::MultipleLoad(urls)),
|
(Some(urls), _) => command::message::app(Message::MultipleLoad(urls)),
|
||||||
(None, Some(path)) if path.is_dir() => command::message::app(Message::FolderLoad(path)),
|
(None, Some(path)) if path.is_dir() => command::message::app(Message::FolderLoad(path)),
|
||||||
_ => app.load(),
|
_ => app.load(), //If there is no url args, we execute load for nothing?
|
||||||
|
//If only one file is loaded, nothing is added to the navbar.
|
||||||
};
|
};
|
||||||
(app, command)
|
(app, command)
|
||||||
}
|
}
|
||||||
|
|
@ -918,9 +918,7 @@ impl Application for App {
|
||||||
// Toggle open state and get clone of node data
|
// Toggle open state and get clone of node data
|
||||||
let node_opt = match self.nav_model.data_mut::<ProjectNode>(id) {
|
let node_opt = match self.nav_model.data_mut::<ProjectNode>(id) {
|
||||||
Some(node) => {
|
Some(node) => {
|
||||||
if let ProjectNode::Folder { open, .. } = node {
|
node.flip_open();
|
||||||
*open = !*open;
|
|
||||||
}
|
|
||||||
Some(node.clone())
|
Some(node.clone())
|
||||||
}
|
}
|
||||||
None => None,
|
None => None,
|
||||||
|
|
@ -1303,9 +1301,58 @@ impl Application for App {
|
||||||
self.update_controls(true);
|
self.update_controls(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Message::PlayNext => {
|
||||||
|
// TODO: known limitations:
|
||||||
|
// 1) if the user collapses the folder entry while a song is playing,
|
||||||
|
// the player will stop at the end of the stream because the current ID may become `Entity(null)`.
|
||||||
|
//
|
||||||
|
// 2) ProjectNode::File does not restrict file types to those supported by GStreamer.
|
||||||
|
// Therefore, if a non-playable file (e.g., a .jpg) is encountered in a folder, it will trigger a
|
||||||
|
// "failed to open file" error and halt the stream.
|
||||||
|
//
|
||||||
|
// 3) if we play the last song of a folder and the next one is already expanded by
|
||||||
|
// user (or because it was played before), the player will collapse it and jump
|
||||||
|
// to the next file/folder after it.
|
||||||
|
|
||||||
|
//first we get info about current media id & position in nav_bar
|
||||||
|
let curr_id = self.nav_model.active();
|
||||||
|
let curr_position = match self.nav_model.position(curr_id) {
|
||||||
|
Some(pos) => pos,
|
||||||
|
None => {
|
||||||
|
log::warn!("Failed to get position of current media: {:?}", curr_id);
|
||||||
|
return self.update(Message::EndOfStream);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//Then we activate the next one in the nav bar and ask to load it
|
||||||
|
if self.nav_model.activate_position(curr_position + 1) {
|
||||||
|
let curr_id = self.nav_model.active();
|
||||||
|
match self.nav_model.data::<ProjectNode>(curr_id) {
|
||||||
|
//The next one is a media file, we play it.
|
||||||
|
Some(ProjectNode::File { .. }) => return self.on_nav_select(curr_id),
|
||||||
|
|
||||||
|
//The next one is a folder. We expand it and recall PlayNext.
|
||||||
|
Some(ProjectNode::Folder { .. }) => {
|
||||||
|
let _ = self.on_nav_select(curr_id);
|
||||||
|
return self.update(Message::PlayNext);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Unknown type. We do nothing.
|
||||||
|
_ => log::warn!(
|
||||||
|
"unknown type: {:?}",
|
||||||
|
self.nav_model.data::<ProjectNode>(curr_id)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return self.update(Message::EndOfStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Message::EndOfStream => {
|
Message::EndOfStream => {
|
||||||
println!("end of stream");
|
println!("end of stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::MissingPlugin(element) => {
|
Message::MissingPlugin(element) => {
|
||||||
if let Some(video) = &mut self.video_opt {
|
if let Some(video) = &mut self.video_opt {
|
||||||
video.set_paused(true);
|
video.set_paused(true);
|
||||||
|
|
@ -1454,7 +1501,7 @@ impl Application for App {
|
||||||
let mut video_player: Element<_> = VideoPlayer::new(video)
|
let mut video_player: Element<_> = VideoPlayer::new(video)
|
||||||
.mouse_hidden(!self.controls)
|
.mouse_hidden(!self.controls)
|
||||||
.on_duration_changed(Message::DurationChanged)
|
.on_duration_changed(Message::DurationChanged)
|
||||||
.on_end_of_stream(Message::EndOfStream)
|
.on_end_of_stream(Message::PlayNext)
|
||||||
.on_missing_plugin(Message::MissingPlugin)
|
.on_missing_plugin(Message::MissingPlugin)
|
||||||
.on_new_frame(Message::NewFrame)
|
.on_new_frame(Message::NewFrame)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,12 @@ impl ProjectNode {
|
||||||
Self::File { name, .. } => name,
|
Self::File { name, .. } => name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn flip_open(&mut self) {
|
||||||
|
if let Self::Folder { open, .. } = self {
|
||||||
|
*open = !*open;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ord for ProjectNode {
|
impl Ord for ProjectNode {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue