@@ -5,9 +5,9 @@ use crate::{
55use std:: ops:: Deref ;
66
77/// Request for loading playback
8- #[ derive( Debug ) ]
8+ #[ derive( Debug , Clone ) ]
99pub struct LoadRequest {
10- pub ( super ) context_uri : String ,
10+ pub ( super ) context : PlayContext ,
1111 pub ( super ) options : LoadRequestOptions ,
1212}
1313
@@ -19,8 +19,14 @@ impl Deref for LoadRequest {
1919 }
2020}
2121
22+ #[ derive( Debug , Clone ) ]
23+ pub ( super ) enum PlayContext {
24+ Uri ( String ) ,
25+ Tracks ( Vec < String > ) ,
26+ }
27+
2228/// The parameters for creating a load request
23- #[ derive( Debug , Default ) ]
29+ #[ derive( Debug , Default , Clone ) ]
2430pub struct LoadRequestOptions {
2531 /// Whether the given tracks should immediately start playing, or just be initially loaded.
2632 pub start_playing : bool ,
@@ -44,7 +50,7 @@ pub struct LoadRequestOptions {
4450///
4551/// Separated into an `enum` to exclude the other variants from being used
4652/// simultaneously, as they are not compatible.
47- #[ derive( Debug ) ]
53+ #[ derive( Debug , Clone ) ]
4854pub enum LoadContextOptions {
4955 /// Starts the context with options
5056 Options ( Options ) ,
@@ -56,7 +62,7 @@ pub enum LoadContextOptions {
5662}
5763
5864/// The available options that indicate how to start the context
59- #[ derive( Debug , Default ) ]
65+ #[ derive( Debug , Default , Clone ) ]
6066pub struct Options {
6167 /// Start the context in shuffle mode
6268 pub shuffle : bool ,
@@ -80,16 +86,30 @@ impl LoadRequest {
8086 /// Create a load request from a `context_uri`
8187 ///
8288 /// For supported `context_uri` see [`SpClient::get_context`](librespot_core::spclient::SpClient::get_context)
89+ ///
90+ /// Equivalent to using [`/me/player/play`](https://developer.spotify.com/documentation/web-api/reference/start-a-users-playback)
91+ /// and providing `context_uri`
8392 pub fn from_context_uri ( context_uri : String , options : LoadRequestOptions ) -> Self {
8493 Self {
85- context_uri,
94+ context : PlayContext :: Uri ( context_uri) ,
95+ options,
96+ }
97+ }
98+
99+ /// Create a load request from a set of `tracks`
100+ ///
101+ /// Equivalent to using [`/me/player/play`](https://developer.spotify.com/documentation/web-api/reference/start-a-users-playback)
102+ /// and providing `uris`
103+ pub fn from_tracks ( tracks : Vec < String > , options : LoadRequestOptions ) -> Self {
104+ Self {
105+ context : PlayContext :: Tracks ( tracks) ,
86106 options,
87107 }
88108 }
89109}
90110
91111/// An item that represent a track to play
92- #[ derive( Debug ) ]
112+ #[ derive( Debug , Clone ) ]
93113pub enum PlayingTrack {
94114 /// Represent the track at a given index.
95115 Index ( u32 ) ,
0 commit comments