1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-05 19:42:03 +02:00

add audio seeking support

This commit is contained in:
Paul Lietar 2015-06-23 18:34:48 +01:00
parent 7ffe996652
commit 4835d25370
7 changed files with 203 additions and 120 deletions

View file

@ -92,44 +92,51 @@ impl StreamManager {
let mut packet = Cursor::new(&data as &[u8]);
let id : ChannelId = packet.read_u16::<BigEndian>().unwrap();
let channel = match self.channels.get_mut(&id) {
Some(ch) => ch,
None => { return; }
};
let mut close = false;
{
let channel = match self.channels.get_mut(&id) {
Some(ch) => ch,
None => { return; }
};
match channel.mode {
ChannelMode::Header => {
let mut length = 0;
match channel.mode {
ChannelMode::Header => {
let mut length = 0;
while packet.position() < data.len() as u64 {
length = packet.read_u16::<BigEndian>().unwrap();
if length > 0 {
let header_id = packet.read_u8().unwrap();
channel.callback.send(StreamEvent::Header(
header_id,
data.clone()
.offset(packet.position() as usize)
.limit(length as usize - 1)
)).unwrap();
while packet.position() < data.len() as u64 {
length = packet.read_u16::<BigEndian>().unwrap();
if length > 0 {
let header_id = packet.read_u8().unwrap();
channel.callback.send(StreamEvent::Header(
header_id,
data.clone()
.offset(packet.position() as usize)
.limit(length as usize - 1)
)).unwrap();
packet.seek(SeekFrom::Current(length as i64 - 1)).unwrap();
packet.seek(SeekFrom::Current(length as i64 - 1)).unwrap();
}
}
if length == 0 {
channel.mode = ChannelMode::Data;
}
}
if length == 0 {
channel.mode = ChannelMode::Data;
}
}
ChannelMode::Data => {
if packet.position() < data.len() as u64 {
channel.callback.send(StreamEvent::Data(
data.clone().offset(packet.position() as usize))).unwrap();
} else {
// TODO: close the channel
ChannelMode::Data => {
if packet.position() < data.len() as u64 {
channel.callback.send(StreamEvent::Data(
data.clone().offset(packet.position() as usize))).unwrap();
} else {
close = true;
}
}
}
}
if close {
self.channels.remove(&id);
}
}
}