Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
820433de
authored
Sep 10, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Call stop() to fully play out remaining audio!
Issue: #707
parent
9bcc00f3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
13 deletions
extensions/opus/src/main/java/com/google/android/exoplayer/ext/opus/LibopusAudioTrackRenderer.java
library/src/main/java/com/google/android/exoplayer/MediaCodecAudioTrackRenderer.java
library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java
library/src/main/java/com/google/android/exoplayer/audio/AudioTrack.java
extensions/opus/src/main/java/com/google/android/exoplayer/ext/opus/LibopusAudioTrackRenderer.java
View file @
820433de
...
...
@@ -212,6 +212,7 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer
if
(
outputBuffer
.
getFlag
(
OpusDecoderWrapper
.
FLAG_END_OF_STREAM
))
{
outputStreamEnded
=
true
;
audioTrack
.
handleEndOfStream
();
decoder
.
releaseOutputBuffer
(
outputBuffer
);
outputBuffer
=
null
;
return
;
...
...
@@ -304,8 +305,7 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer
@Override
protected
boolean
isEnded
()
{
return
outputStreamEnded
&&
(!
audioTrack
.
hasPendingData
()
||
!
audioTrack
.
hasEnoughDataToBeginPlayback
());
return
outputStreamEnded
&&
!
audioTrack
.
hasPendingData
();
}
@Override
...
...
library/src/main/java/com/google/android/exoplayer/MediaCodecAudioTrackRenderer.java
View file @
820433de
...
...
@@ -265,10 +265,7 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
@Override
protected
boolean
isEnded
()
{
// We've exhausted the output stream, and the AudioTrack has either played all of the data
// submitted, or has been fed insufficient data to begin playback.
return
super
.
isEnded
()
&&
(!
audioTrack
.
hasPendingData
()
||
!
audioTrack
.
hasEnoughDataToBeginPlayback
());
return
super
.
isEnded
()
&&
!
audioTrack
.
hasPendingData
();
}
@Override
...
...
@@ -366,6 +363,11 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
return
false
;
}
@Override
protected
void
onOutputStreamEnded
()
{
audioTrack
.
handleEndOfStream
();
}
protected
void
handleDiscontinuity
()
{
// Do nothing
}
...
...
library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java
View file @
820433de
...
...
@@ -720,6 +720,17 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
}
/**
* Invoked when the output stream ends, meaning that the last output buffer has been processed
* and the {@link MediaCodec#BUFFER_FLAG_END_OF_STREAM} flag has been propagated through the
* decoder.
* <p>
* The default implementation is a no-op.
*/
protected
void
onOutputStreamEnded
()
{
// Do nothing.
}
/**
* Determines whether the existing {@link MediaCodec} should be reconfigured for a new format by
* sending codec specific initialization data at the start of the next input buffer. If true is
* returned then the {@link MediaCodec} instance will be reconfigured in this way. If false is
...
...
@@ -846,6 +857,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
maybeInitCodec
();
}
else
{
outputStreamEnded
=
true
;
onOutputStreamEnded
();
}
}
...
...
library/src/main/java/com/google/android/exoplayer/audio/AudioTrack.java
View file @
820433de
...
...
@@ -562,6 +562,17 @@ public final class AudioTrack {
return
result
;
}
/**
* Ensures that the last data passed to {@link #handleBuffer(ByteBuffer, int, int, long)} is
* played out in full.
*/
public
void
handleEndOfStream
()
{
if
(
audioTrack
!=
null
)
{
// Required to ensure that the media written to the AudioTrack is played out in full.
audioTrack
.
stop
();
}
}
@TargetApi
(
21
)
private
static
int
writeNonBlockingV21
(
android
.
media
.
AudioTrack
audioTrack
,
ByteBuffer
buffer
,
int
size
)
{
...
...
@@ -575,13 +586,6 @@ public final class AudioTrack {
||
audioTrackUtil
.
overrideHasPendingData
());
}
/** Returns whether enough data has been supplied via {@link #handleBuffer} to begin playback. */
public
boolean
hasEnoughDataToBeginPlayback
()
{
// The value of minBufferSize can be slightly less than what's actually required for playback
// to start, hence the multiplication factor.
return
submittedBytes
>
(
minBufferSize
*
3
)
/
2
;
}
/** Sets the playback volume. */
public
void
setVolume
(
float
volume
)
{
if
(
this
.
volume
!=
volume
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment