Skip to content

Commit 56dc1f8

Browse files
committed
Sync with master
2 parents 7eacb54 + 0f44d43 commit 56dc1f8

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ rust:
44
- beta
55
- nightly
66
- stable
7+
os:
8+
- linux
9+
- osx
710
install:
811
- wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz -O sdl2.tar.gz
912
- tar xzf sdl2.tar.gz
@@ -24,7 +27,8 @@ install:
2427
before_script:
2528
- |
2629
pip install 'travis-cargo<0.2' --user &&
27-
export PATH=$HOME/.local/bin:$PATH
30+
export PATH=$HOME/.local/bin:$PATH &&
31+
export PATH=~/Library/Python/2.7/bin:$PATH
2832
script:
2933
- |
3034
travis-cargo build -- --features "gfx image ttf mixer" &&

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ breaking exisitng code too much.
1818
* Adds the `unsafe_textures` feature to this crate, allowing to get rid of the lifetimes
1919
in `Texture`s in the `render` module.
2020

21+
[PR #704](https://github.com/Rust-SDL2/rust-sdl2/pull/704)
22+
23+
* Adds the `Music::from_static_bytes` function, which creates a Music instance with the
24+
static lifetime from a buffer that also has a static lifetime.
25+
2126
### v0.30
2227

2328
Re-exported sdl2\_sys as sdl2::sys

src/sdl2/mixer/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use std::ffi::{CString, CStr};
2727
use std::str::from_utf8;
2828
use std::borrow::ToOwned;
2929
use std::path::Path;
30-
use libc::{c_int, uint16_t, c_double, c_uint};
30+
use libc::{c_int, uint16_t, c_double, c_uint, c_void};
3131
use ::get_error;
3232
use ::rwops::RWops;
3333
use ::version::Version;
@@ -790,6 +790,28 @@ impl<'a> Music<'a> {
790790
}
791791
}
792792

793+
/// Load music from a static byte buffer.
794+
pub fn from_static_bytes(buf: &'static [u8]) -> Result<Music<'static>, String> {
795+
let rw = unsafe {
796+
::sys::rwops::SDL_RWFromConstMem(buf.as_ptr() as *const c_void, buf.len() as c_int)
797+
};
798+
799+
if rw.is_null() {
800+
return Err(get_error());
801+
}
802+
803+
let raw = unsafe { ffi::Mix_LoadMUS_RW(rw, 0) };
804+
if raw.is_null() {
805+
Err(get_error())
806+
} else {
807+
Ok(Music {
808+
raw: raw,
809+
owned: true,
810+
_marker: PhantomData,
811+
})
812+
}
813+
}
814+
793815
/// The file format encoding of the music.
794816
pub fn get_type(&self) -> MusicType {
795817
let ret = unsafe { ffi::Mix_GetMusicType(self.raw) as i32 } as c_uint;

0 commit comments

Comments
 (0)