与AACDe codeR开始新的流 [英] Start new stream with AACDecoder
问题描述
我做了无线电应用(调等)
的情况:
- 当电台开始首先它播放音频广告,然后打开收音机(AD和收音机2 diferents流)
- 当AACPlayer当前正在播放的音乐和用户更改电台
两个问题:
- 当广告结束AACPlayer需要停下来,并与另一个URL启动
- 当用户选择另一个无线它是相同的
随着AACDe codeR库只有两个方法
- 启动()
- 停止()
这些方法可以彼此干涉并在<强>不确定状态获得玩家强>
我开始与这个code球员:
公共无效启动(字符串URL)抛出异常{
如果(MPLAYER == NULL){
MPLAYER =新的多人游戏(本);
}
mPlayer.playAsync(URL);
mState = StreamingState prePARING。
}
和停止这样的:
公共无效停止(){
如果(MPLAYER == NULL){
返回;
}
尝试{
mPlayer.stop();
MPLAYER = NULL;
}赶上(例外五){
}
的setState(StreamingState.STOPPING);
}
我用这个回调接口:
静态接口RadioPlayerCallBack {
公共无效radioPlayerStarted();
公共无效radioPlayerStopped(INT PERF);
公共无效radioPlayerException(Throwable的E);
公共无效radioPlayerMetadata(字符串键,字符串值);
公共无效radioPlayerPCMFeedBuffer(布尔IsPlaying模块,诠释audioBufferSizeMs,诠释audioBufferCapacityMs);
}
和我更新与此枚举球员的状态:
公共枚举StreamingState {
空的,//媒体播放器或休息releasedS
创建的,创建//准备prepare
prePARING,// preparing ...
prePARED,// prepared
STARTED,//开始,也许打(准备比赛)
顿了顿,//暂停(媒体播放器准备好了!)
已停止,停止//而不是prepared玩
ERROR,//发生错误,MediaPlayer正在reseted
停,// startAsync停止后
}
我无法找到一个解决办法做的停止() - >启动(URL)上的播放器,已在播放流,同时确保状态玩家(ⅰ必须在帐户中的网络的等待时间)
我怎样才能做到这一点?
修改
下面是如何做事的快速视图:
[ PlayerActivity - > StreamingService - > PlayerObject ]
为了:
点击按钮播放 - >调用方法playRadio从StreamingService通过实例从serviceConnection->调用方法该剧从PlayerObject-> playerState =开始 - >法playerStarted自动叫 - > playerState =开始 - 从StreamingService>回调方法 - >广播意图告知用户界面 - > UI获得的意图和更新接口...
下面是广播接收器:
最后的私人广播接收器mPlayBackReceiver =新的广播接收器(){ @覆盖
公共无效的onReceive(上下文的背景下,意图意图){
串actionString = intent.getAction();
如果(actionString == ServiceStreaming.SERVICE_PLAY){
}否则如果(actionString == ServiceStreaming.SERVICE_STOP){
}否则如果(actionString == ServiceStreaming.SERVICE_LOADING){
}否则如果(actionString == ServiceStreaming.SERVICE_ERROR){
}否则如果(actionString == ServiceStreaming.SERVICE_KILLED){
}
}
};
Somethimes我得到这个异常:
10月6日至4日:15:43.531:E / AudioTrack(8218):AudioFlinger无法创建跟踪,状态:-12
10月6日至4日:15:43.531:E / AudioTrack-JNI(8218):错误初始化AudioTrack
10月6日至4日:15:43.531:E / android.media.AudioTrack(8218):错误code初始化AudioTrack时-20。
10月6日至4日:15:43.531:E / PCMFeed(8218):错误播放饲料:-3
10月6日至4日:15:43.541:E / BufferReader(8218):异常时阅读:产生java.net.SocketException:套接字关闭
10月6日至4日:15:43.901:A / libc的(8218):在0x76652748(code = 1)致命信号11(SIGSEGV),螺纹8955(螺纹5266)
10月6日至4日:15:43.911:E / AACPlayer(8218):playAsync():
10月6日至4日:15:43.911:E / AACPlayer(8218):java.lang.IllegalStateException
10月6日至4日:15:43.911:E / AACPlayer(8218):在com.spoledge.aacde coder.De coder.start(德coder.java:231)
10月6日至4日:15:43.911:E / AACPlayer(8218):在com.spoledge.aacde coder.AACPlayer.playImpl(AACPlayer.java:424)
10月6日至4日:15:43.911:E / AACPlayer(8218):在com.spoledge.aacde coder.AACPlayer.play(AACPlayer.java:386)
10月6日至4日:15:43.911:E / AACPlayer(8218):在com.spoledge.aacde coder.AACPlayer.play(AACPlayer.java:338)
10月6日至4日:15:43.911:E / AACPlayer(8218):在com.spoledge.aacde coder.AACPlayer $ 1.run(AACPlayer.java:296)
10月6日至4日:15:43.911:E / AACPlayer(8218):在java.lang.Thread.run(Thread.java:841)
我觉得应该通过回调函数playercallback界面完成可以在这里找到:
<一个href=\"https://$c$c.google.com/p/aacplayer-android/source/browse/trunk/src/com/spoledge/aacplayer/PlayerCallback.java\" rel=\"nofollow\">https://$c$c.google.com/p/aacplayer-android/source/browse/trunk/src/com/spoledge/aacplayer/PlayerCallback.java
和在AACPlayer本身的功能是:
/ **
*设定PlayerCallback。
*注:本应设置之前的任何的播放方法被调用。
* /
公共无效setPlayerCallback(PlayerCallback playerCallback)
然后当玩家停止执行该功能:
/ **
*此方法,当播放机停止调用。
*注:__after__此方法的方法playerException也可能被调用。
* /
公共无效playerStopped(INT PERF);
只是把你的逻辑重新启动这个功能里面。
链接aacPlayer来源:
<一个href=\"https://$c$c.google.com/p/aacplayer-android/source/browse/trunk/src/com/spoledge/aacplayer/AACPlayer.java\" rel=\"nofollow\">https://$c$c.google.com/p/aacplayer-android/source/browse/trunk/src/com/spoledge/aacplayer/AACPlayer.java
修改1
有使用aacPlayer活动源的链接:
<一href=\"https://$c$c.google.com/p/aacplayer-android/source/browse/trunk/src/com/spoledge/aacplayer/AACPlayerActivity.java\" rel=\"nofollow\">https://$c$c.google.com/p/aacplayer-android/source/browse/trunk/src/com/spoledge/aacplayer/AACPlayerActivity.java
您应该注意到,在回调函数处理程序使用和code是在球员的线程不执行单独的线程中执行:
公共无效playerStopped(最终诠释PERF){
uiHandler.post(新的Runnable(){
公共无效的run(){
enableButtons();
...
playerStarted = FALSE;
}
});
}
Somethimes我得到这个异常:
10月6日至4日:15:43.531:E / AudioTrack(8218):AudioFlinger无法创建跟踪,状态:-12
10月6日至4日:15:43.531:E / AudioTrack-JNI(8218):错误初始化AudioTrack
10月6日至4日:15:43.531:E / android.media.AudioTrack(8218):错误code初始化AudioTrack时-20。
10月6日至4日:15:43.531:E / PCMFeed(8218):错误播放饲料:-3
10月6日至4日:15:43.541:E / BufferReader(8218):异常时阅读:产生java.net.SocketException:套接字关闭
10月6日至4日:15:43.901:A / libc的(8218):在0x76652748(code = 1)致命信号11(SIGSEGV),螺纹8955(螺纹5266)
10月6日至4日:15:43.911:E / AACPlayer(8218):playAsync():
10月6日至4日:15:43.911:E / AACPlayer(8218):java.lang.IllegalStateException
10月6日至4日:15:43.911:E / AACPlayer(8218):在com.spoledge.aacde coder.De coder.start(德coder.java:231)
10月6日至4日:15:43.911:E / AACPlayer(8218):在com.spoledge.aacde coder.AACPlayer.playImpl(AACPlayer.java:424)
10月6日至4日:15:43.911:E / AACPlayer(8218):在com.spoledge.aacde coder.AACPlayer.play(AACPlayer.java:386)
10月6日至4日:15:43.911:E / AACPlayer(8218):在com.spoledge.aacde coder.AACPlayer.play(AACPlayer.java:338)
10月6日至4日:15:43.911:E / AACPlayer(8218):在com.spoledge.aacde coder.AACPlayer $ 1.run(AACPlayer.java:296)
10月6日至4日:15:43.911:E / AACPlayer(8218):在java.lang.Thread.run(Thread.java:841)
修改2
链接simmilar问题:
<一个href=\"http://stackoverflow.com/questions/17527996/android-application-crashes-after-generating-an-audio-signal-a-few-times\">Android产生音频信号的几次
在应用程序崩溃<一个href=\"http://stackoverflow.com/questions/11964623/audioflinger-could-not-create-track-status-12\">AudioFlinger无法创建轨道。状态:-12
I'm doing a radio Application (Tune In like)
The situations :
- When the radio start at first it play an audio AD and then start the radio (AD and radio are 2 diferents streams)
- When a AACPlayer is currently playing music and the user change station
Two problems :
- When the ad finish the AACPlayer need to stop and start with another URL
- When the user select another radio it is the same
With the AACDecoder library there are only two methods - start() - stop()
Those methods can interfere with each other and get the player in an indeterminate state
I start a player with this code :
public void start(String url) throws Exception {
if (mPlayer == null) {
mPlayer = new MultiPlayer(this);
}
mPlayer.playAsync(url);
mState = StreamingState.PREPARING;
}
and stop it like this :
public void stop() {
if (mPlayer == null) {
return;
}
try {
mPlayer.stop();
mPlayer = null;
} catch (Exception e) {
}
setState(StreamingState.STOPPING);
}
I use this callback interface :
static interface RadioPlayerCallBack {
public void radioPlayerStarted();
public void radioPlayerStopped(int perf);
public void radioPlayerException(Throwable e);
public void radioPlayerMetadata(String key, String value);
public void radioPlayerPCMFeedBuffer(boolean isPlaying, int audioBufferSizeMs, int audioBufferCapacityMs);
}
and i update the state of the player with this enum :
public enum StreamingState {
EMPTY, // media player rested or releasedS
CREATED, // created ready to prepare
PREPARING, // preparing...
PREPARED, // prepared
STARTED, // started, and maybe playing (ready to play)
PAUSED, // paused (media player ready!)
STOPPED, // stopped and not prepared to play
ERROR, // an error occured, mediaplayer is reseted
STOPPING, // startAsync after stop
}
I can't find a solution to do Stop() -> start(url) on a player that is already playing a stream, while securing the state of the player (i must take the latency of the network in account)
How can i achieve that ?
EDIT
Here is a quick view of how things are done :
[PlayerActivity -> StreamingService -> PlayerObject]
In order :
Click on button play -> call method playRadio from StreamingService through the instance got from serviceConnection-> call method play from PlayerObject-> playerState=starting -> method playerStarted auto-called -> playerState=started -> callback method from StreamingService -> broadcast an intent to inform UI -> ui get the intent and update interface...
Here is the BroadcastReceiver :
final private BroadcastReceiver mPlayBackReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String actionString = intent.getAction();
if (actionString == ServiceStreaming.SERVICE_PLAY) {
} else if (actionString == ServiceStreaming.SERVICE_STOP) {
} else if (actionString == ServiceStreaming.SERVICE_LOADING) {
} else if (actionString == ServiceStreaming.SERVICE_ERROR) {
} else if (actionString == ServiceStreaming.SERVICE_KILLED) {
}
}
};
Somethimes i get this exception :
06-04 10:15:43.531: E/AudioTrack(8218): AudioFlinger could not create track, status: -12
06-04 10:15:43.531: E/AudioTrack-JNI(8218): Error initializing AudioTrack
06-04 10:15:43.531: E/android.media.AudioTrack(8218): Error code -20 when initializing AudioTrack.
06-04 10:15:43.531: E/PCMFeed(8218): error in playback feed: -3
06-04 10:15:43.541: E/BufferReader(8218): Exception when reading: java.net.SocketException: Socket closed
06-04 10:15:43.901: A/libc(8218): Fatal signal 11 (SIGSEGV) at 0x76652748 (code=1), thread 8955 (Thread-5266)
06-04 10:15:43.911: E/AACPlayer(8218): playAsync():
06-04 10:15:43.911: E/AACPlayer(8218): java.lang.IllegalStateException
06-04 10:15:43.911: E/AACPlayer(8218): at com.spoledge.aacdecoder.Decoder.start(Decoder.java:231)
06-04 10:15:43.911: E/AACPlayer(8218): at com.spoledge.aacdecoder.AACPlayer.playImpl(AACPlayer.java:424)
06-04 10:15:43.911: E/AACPlayer(8218): at com.spoledge.aacdecoder.AACPlayer.play(AACPlayer.java:386)
06-04 10:15:43.911: E/AACPlayer(8218): at com.spoledge.aacdecoder.AACPlayer.play(AACPlayer.java:338)
06-04 10:15:43.911: E/AACPlayer(8218): at com.spoledge.aacdecoder.AACPlayer$1.run(AACPlayer.java:296)
06-04 10:15:43.911: E/AACPlayer(8218): at java.lang.Thread.run(Thread.java:841)
I think it should be done by callback function playercallback interface can be found here:
and the function in AACPlayer itself is :
/**
* Sets the PlayerCallback.
* NOTE: this should be set BEFORE any of the play methods are called.
*/
public void setPlayerCallback( PlayerCallback playerCallback )
then when player stops this function is executed:
/**
* This method is called when the player is stopped.
* Note: __after__ this method the method playerException might be also called.
*/
public void playerStopped( int perf );
just put your restarting logic inside this function.
link to sources of aacPlayer:
EDIT 1
there is a link to source of Activity using aacPlayer : https://code.google.com/p/aacplayer-android/source/browse/trunk/src/com/spoledge/aacplayer/AACPlayerActivity.java
You should notice that in callback function a Handler is used and a code is executed in separate thread not executed in players thread:
public void playerStopped( final int perf ) {
uiHandler.post( new Runnable() {
public void run() {
enableButtons();
...
playerStarted = false;
}
});
}
Somethimes i get this exception :
06-04 10:15:43.531: E/AudioTrack(8218): AudioFlinger could not create track, status: -12
06-04 10:15:43.531: E/AudioTrack-JNI(8218): Error initializing AudioTrack
06-04 10:15:43.531: E/android.media.AudioTrack(8218): Error code -20 when initializing AudioTrack.
06-04 10:15:43.531: E/PCMFeed(8218): error in playback feed: -3
06-04 10:15:43.541: E/BufferReader(8218): Exception when reading: java.net.SocketException: Socket closed
06-04 10:15:43.901: A/libc(8218): Fatal signal 11 (SIGSEGV) at 0x76652748 (code=1), thread 8955 (Thread-5266)
06-04 10:15:43.911: E/AACPlayer(8218): playAsync():
06-04 10:15:43.911: E/AACPlayer(8218): java.lang.IllegalStateException
06-04 10:15:43.911: E/AACPlayer(8218): at com.spoledge.aacdecoder.Decoder.start(Decoder.java:231)
06-04 10:15:43.911: E/AACPlayer(8218): at com.spoledge.aacdecoder.AACPlayer.playImpl(AACPlayer.java:424)
06-04 10:15:43.911: E/AACPlayer(8218): at com.spoledge.aacdecoder.AACPlayer.play(AACPlayer.java:386)
06-04 10:15:43.911: E/AACPlayer(8218): at com.spoledge.aacdecoder.AACPlayer.play(AACPlayer.java:338)
06-04 10:15:43.911: E/AACPlayer(8218): at com.spoledge.aacdecoder.AACPlayer$1.run(AACPlayer.java:296)
06-04 10:15:43.911: E/AACPlayer(8218): at java.lang.Thread.run(Thread.java:841)
edit 2
link to simmilar questions:
Android Application crashes after generating an audio signal a few times
AudioFlinger could not create track. status: -12
这篇关于与AACDe codeR开始新的流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!