我正在尝试从Firebase获取url并将其提供给mediaplayer.setDataSource,但我得到一个错误提示:-`
.native-input.sc-ion-input-md {
max-width: 20% !important;
}
input native-input sc-ion-input-md {
max-width: 20% !important;
}
这是我的代码:-
java.lang.IllegalStateException
at android.media.MediaPlayer._setDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:991)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:944)
at mks.master.musest.home$onCreateView$16$1$1.onDataChange(home.kt:425)
at com.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:45)
at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5019)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
`
主要错误在这部分`var mediaplayer:MediaPlayeria
mediaplayer=MediaPlayer()
firebase= Firebase(link+"song2song")
firebase.addValueEventListener(object:ValueEventListener{
override fun onCancelled(p0: FirebaseError?) {
}
override fun onDataChange(p0: DataSnapshot) {
mediaplayer.setDataSource(p0.getValue(String()::class.java))
mediaplayer.prepareAsync()
}
})`
答案 0 :(得分:0)
您应先致电reset()
,然后再致电setDataSource()
。
在Android参考中查看以下state diagram,可以使您清楚地了解MediaPlayer
的不同状态
另外This table显示setDataSource()
只能从空闲状态执行。