来自 AudioTrack 流的通知消息
我已经实现了一个写入 AudioTrack
对象的 PCM 解码器。
一切看起来都很棒,但是,当最后写入的块停止播放时,我需要从 AudioTrack 对象获得某种通知。
我注意到有一些回调方法,例如 setNotificationMarkerPosition,
但是,我找不到任何有关如何使用它们的详细文档。
提前致谢!
I've implemented a PCM decoder that writes to an AudioTrack
object.
Everything seems great, however, I need to get some sort of notification from the AudioTrack
object when the last written chunk has stopped playing.
I've noticed that there are callback methods such as setNotificationMarkerPosition,
however, I couldn't find any extensive documentation as how to use them.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获取
AudioTrack
回调,您可以设置标记回调或使用定期回调。我看过有关标记问题的报告,因此您可能想同时尝试这两种方法。对于标记回调,首先使用您想要调用的任何帧号调用
setNotificationMarkerPosition
。对于定期回调,请改为调用
setPositionNotificationPeriod
,它将每 x 帧调用一次。无论哪种方式,您都需要调用
setPlaybackPositionUpdateListener
来注册回调。这将调用两个方法,如果到达标记,则调用onMarkerReached
,或者每隔设定数量的帧调用onPeriodicNotification
。您可以选择使用其中之一,或两者都使用。两个回调都引用您用来设置它的AudioTrack
实例。默认情况下,它将在创建
AudioTrack
实例的同一线程中回调。或者,您可以在注册回调时传递处理程序以将其发送到另一个线程。To get an
AudioTrack
callback, you could set a marker callback or use the periodic callback. I've seen reports of problems with the marker, so you may want to try both.For the marker callback, first call
setNotificationMarkerPosition
with whatever frame number you want a call for.For a periodic callback, instead call
setPositionNotificationPeriod
and it will call every x frames.Either way, you'll need to call
setPlaybackPositionUpdateListener
to register the callback. This will call two methods,onMarkerReached
if it reaches a marker, oronPeriodicNotification
every set number of frames. You can choose to use one or the other, or both. Both callbacks refer the instance ofAudioTrack
you used to set it.By default, it will call back in the same thread the
AudioTrack
instance was created. Alternatively, you can pass a handler when you register the callbacks to send it to another thread.