mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
core API: move subfile.rs to player.rs
This commit is contained in:
parent
d7fa1464ff
commit
496a802248
3 changed files with 40 additions and 42 deletions
|
@ -8,11 +8,9 @@ use std::process::Command;
|
|||
|
||||
mod int128;
|
||||
mod spotify_id;
|
||||
mod subfile;
|
||||
|
||||
pub use util::int128::u128;
|
||||
pub use util::spotify_id::{SpotifyId, FileId};
|
||||
pub use util::subfile::Subfile;
|
||||
|
||||
pub fn rand_vec<G: Rng, R: Rand>(rng: &mut G, size: usize) -> Vec<R> {
|
||||
rng.gen_iter().take(size).collect()
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
use std::io::{Read, Seek, SeekFrom, Result};
|
||||
|
||||
pub struct Subfile<T: Read + Seek> {
|
||||
stream: T,
|
||||
offset: u64,
|
||||
}
|
||||
|
||||
impl<T: Read + Seek> Subfile<T> {
|
||||
pub fn new(mut stream: T, offset: u64) -> Subfile<T> {
|
||||
stream.seek(SeekFrom::Start(offset)).unwrap();
|
||||
Subfile {
|
||||
stream: stream,
|
||||
offset: offset,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Read + Seek> Read for Subfile<T> {
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
||||
self.stream.read(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Read + Seek> Seek for Subfile<T> {
|
||||
fn seek(&mut self, mut pos: SeekFrom) -> Result<u64> {
|
||||
pos = match pos {
|
||||
SeekFrom::Start(offset) => SeekFrom::Start(offset + self.offset),
|
||||
x => x,
|
||||
};
|
||||
|
||||
let newpos = try!(self.stream.seek(pos));
|
||||
if newpos > self.offset {
|
||||
Ok(newpos - self.offset)
|
||||
} else {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,16 @@
|
|||
use futures::sync::oneshot;
|
||||
use futures::{future, Future};
|
||||
use std;
|
||||
use std::borrow::Cow;
|
||||
use std::io::{Read, Seek, SeekFrom, Result};
|
||||
use std::mem;
|
||||
use std::sync::mpsc::{RecvError, TryRecvError, RecvTimeoutError};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std;
|
||||
|
||||
use core::config::{Bitrate, PlayerConfig};
|
||||
use core::session::Session;
|
||||
use core::util::{self, SpotifyId, Subfile};
|
||||
use core::util::{self, SpotifyId};
|
||||
|
||||
use audio_backend::Sink;
|
||||
use audio::{AudioFile, AudioDecrypt};
|
||||
|
@ -478,3 +479,40 @@ impl ::std::fmt::Debug for PlayerCommand {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Subfile<T: Read + Seek> {
|
||||
stream: T,
|
||||
offset: u64,
|
||||
}
|
||||
|
||||
impl<T: Read + Seek> Subfile<T> {
|
||||
pub fn new(mut stream: T, offset: u64) -> Subfile<T> {
|
||||
stream.seek(SeekFrom::Start(offset)).unwrap();
|
||||
Subfile {
|
||||
stream: stream,
|
||||
offset: offset,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Read + Seek> Read for Subfile<T> {
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
||||
self.stream.read(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Read + Seek> Seek for Subfile<T> {
|
||||
fn seek(&mut self, mut pos: SeekFrom) -> Result<u64> {
|
||||
pos = match pos {
|
||||
SeekFrom::Start(offset) => SeekFrom::Start(offset + self.offset),
|
||||
x => x,
|
||||
};
|
||||
|
||||
let newpos = try!(self.stream.seek(pos));
|
||||
if newpos > self.offset {
|
||||
Ok(newpos - self.offset)
|
||||
} else {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue