2017-06-02 120 views
0

我知道有一些类似的问题,但没有人回答我的问题。当我点击一个按钮时,媒体播放器被调用,并且这出现在日志中。MediaPlayer中的错误:E/MediaPlayer:错误(1,-19) - Android

06-02 00:20:38.980 26035-26035/myapp.com.facadezpontos E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present 
06-02 00:20:39.019 26035-26035/myapp.com.facadezpontos E/MediaPlayer: Should have subtitle controller already set 
06-02 00:20:39.026 26035-26035/myapp.com.facadezpontos E/MediaPlayer: Should have subtitle controller already set 

一段时间后,这条消息以上是由该波纹管取代了,声音通过媒体播放器提供不玩了。

06-02 00:23:21.032 28749-28749/myapp.com.facadezpontos E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present 
06-02 00:23:21.076 28749-28749/myapp.com.facadezpontos E/MediaPlayer: Should have subtitle controller already set 
06-02 00:23:21.090 28749-28749/myapp.com.facadezpontos E/MediaPlayer: Should have subtitle controller already set 
06-02 00:23:21.396 28749-28772/myapp.com.facadezpontos E/MediaPlayer: error (1, -19) 
06-02 00:23:21.396 28749-28749/myapp.com.facadezpontos E/MediaPlayer: Error (1,-19) 

这是在MediaPlayer

public void buttonClick(Context context, MediaPlayer mp){ 
     mp = MediaPlayer.create(context, R.raw.bubble_nice); 
     mp.start(); 
    } 
+0

的可能的复制(https://stackoverflow.com/questions/24501086/why-mediaplayer -throws-not-present-error-when-creating-instance-of-it) – Isaac

+0

这个问题没有解决问题 – Felipe

+0

@Felipe你解决了这个问题吗? –

回答

0

我解决了这个问题的代码!

我改变了我称之为声音文件的方式,下面是我如何做到的。

我把这个文件放在资产里面,以使它工作。

if(mp.isPlaying()) 
    { 
     mp.stop(); 
    } 

    try { 
     mp.reset(); 
     AssetFileDescriptor afd; 
     afd = getAssets().openFd("AudioFile.mp3"); 
     mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); 
     mp.prepare(); 
     mp.start(); 
    } catch (IllegalStateException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

我得到这个从这里:为什么创建的MediaPlayer它的实例时抛出不存在错误] android - how to make a button click play a sound file every time it been pressed?