Merge pull request #15980 from mrcdk/audio_stream_get_length

Expose audio streams get_length()
This commit is contained in:
Rémi Verschelde 2018-01-30 13:43:34 +01:00 committed by GitHub
commit ed6bf28014
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 39 deletions

View file

@ -115,7 +115,7 @@ void AudioStreamPlaybackOGGVorbis::seek(float p_time) {
if (!active)
return;
if (p_time >= get_length()) {
if (p_time >= vorbis_stream->get_length()) {
p_time = 0;
}
frames_mixed = uint32_t(vorbis_stream->sample_rate * p_time);
@ -123,11 +123,6 @@ void AudioStreamPlaybackOGGVorbis::seek(float p_time) {
stb_vorbis_seek(ogg_stream, frames_mixed);
}
float AudioStreamPlaybackOGGVorbis::get_length() const {
return vorbis_stream->length;
}
AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() {
if (ogg_alloc.alloc_buffer) {
stb_vorbis_close(ogg_stream);
@ -261,6 +256,11 @@ float AudioStreamOGGVorbis::get_loop_offset() const {
return loop_offset;
}
float AudioStreamOGGVorbis::get_length() const {
return length;
}
void AudioStreamOGGVorbis::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_data", "data"), &AudioStreamOGGVorbis::set_data);

View file

@ -71,8 +71,6 @@ public:
virtual float get_playback_position() const;
virtual void seek(float p_time);
virtual float get_length() const; //if supported, otherwise return 0
AudioStreamPlaybackOGGVorbis() {}
~AudioStreamPlaybackOGGVorbis();
};
@ -112,6 +110,8 @@ public:
void set_data(const PoolVector<uint8_t> &p_data);
PoolVector<uint8_t> get_data() const;
virtual float get_length() const; //if supported, otherwise return 0
AudioStreamOGGVorbis();
virtual ~AudioStreamOGGVorbis();
};