2017-08-07 34 views
0

我试图建立一个录音机应用程序,MainActivity记录,其他活动是为显示所有记录和媒体播放器的列表视图,媒体播放器出现问题,它工作正常在我构建第二个活动之前,然后开始了一些本地错误之前,我想我会构建第二个活动并将修复它......仍然会出现一些本地错误。请帮我解决它!试图从列表中播放MediaPlayer时出错

我迷上了filePath,看起来不错。

Log.d(filePath,“路径存在”);

08-08 12:05:49.298 2801-2801/com.example.tsuryohananov.voicerecorder D // storage/emulated/0/Recordings/07-08-2017 06:37:15 PM.mp4:路径存在

我的代码(记录活动):

public class RecordsActivity extends AppCompatActivity { 

    Button play; 
    static ListView recordList; 
    ArrayAdapter<String> listAdapter; 
    String recordToPlay; 
    MediaPlayer mp; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_records); 

     mp = new MediaPlayer(); 

     play = (Button) findViewById(R.id.playbutton); 
     recordList = (ListView) findViewById(R.id.list); 

// Adapter with an ArrayList from the MainActivity that contains all the file names. 

     listAdapter = new ArrayAdapter<String>(RecordsActivity.this, R.layout.support_simple_spinner_dropdown_item, MainActivity.listRecord); 
     recordList.setAdapter(listAdapter); 


     recordList.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       //int chosenPosition = position; 
       recordToPlay = listAdapter.getItem(position); 

//made that toast to check if the name of the file set properly, it looks like it is. 

       Toast.makeText(getApplicationContext(), recordToPlay+ " Chosen", Toast.LENGTH_LONG).show(); 
       } 
      }); 

      play.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        String filePath = Environment.getExternalStorageDirectory()+"/Recordings/"+recordToPlay; 


        try { 
         mp.setDataSource(filePath); 
         mp.prepare(); 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 
        mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
         @Override 
         public void onPrepared(MediaPlayer mediaPlayer) { 
          //finalMp1.start(); 
          mp.start(); 

         } 
        }); 

       } 
      }); 
     } 
    } 

logcat-

08-07 18:01:25.330 9157-9157 /? I/zygote:不迟到启用-Xcheck:jni (已在)08-07 18:01:25.445 9157-9157 /? W/zygote:意外的CPU 变种X86使用默认值:x86 08-07 18:01:25.822 9157-9157/com.example.tsuryohananov.voicerecorder I/InstantRun: 开始即时运行服务器:主进程08-07 18:01:26.392 9157-9206/com.example.tsuryohananov.voicerecorder d/OpenGLRenderer: 慧深GL管道

[08-07 18:01:26.423 9157:9206 d /] HostConnection :: get()建立新主机连接0xa3d645c0,tid 9206 08-07 18:01:26.655 9157-9206/com.example.tsuryohananov.voicerecorder I/OpenGLRenderer: 已初始化的EGL,版本1.4 08-07 18:01:26.655 9157-9206/com.example.tsuryohananov.voicerecorder d/OpenGLRenderer: 交换行为1月8日至7日18:01:26.655 9157-9206/com.example.tsuryohananov.voicerecorder W/OpenGLRenderer: 无法选择与EGL_SWAP_BEHAVIOR_PRESERVED配置,重试 不... 08-07 18:01:26.655 9157-9206/com.example.tsuryohananov.voicerecorder d/OpenGLRenderer: 交换行为0 08-07 18:01:26.657 9157-9206/com.example.tsuryohananov.voicerecorder D/EGL_emulation: eglCreateContext:0xa139c420:maj 2 min 0 rcv 2 08-07 18:01:26.658 9157-9206/com.example.tsuryohananov.voicerecorder D/EGL_emulation: eglMakeCurrent:0xa139c420:ver 2 0(tinfo 0xa265da d0)08-07 18:01:26.664 9157-9206/com.example.tsuryohananov.voicerecorder W /[email protected] :: Mapper:getService:found null hwbinder interface 08-07 18: 01:26.667 9157-9206/com.example.tsuryohananov.voicerecorder I/vndksupport:sphal 命名空间未配置用于此进程。改为从当前命名空间加载 /system/lib/hw/gralloc.ranchu.so。 08-07 18:01:26.718 9157-9206/com.example.tsuryohananov.voicerecorder d/EGL_emulation:eglMakeCurrent:0xa139c420:第二版0(TINFO 0xa265dad0)08-07 18:01:34.512 9157-9206/com.example.tsuryohananov.voicerecorder D/EGL_emulation: eglMakeCurrent:0xa139c420:ver 2 0(tinfo 0xa265dad0)08-07 18:01:34.535 9157-9183/com.example.tsuryohananov。录音机 I/zygote:后台并发复制GC释放4737(843KB) AllocSpace对象,0(0B)LOS对象,64%空闲,855KB/2MB,暂停 总计10.284ms 110.547ms 08-07 18:01:34.558 9157 -9168/com.example.tsuryohananov.voicerecorder I/zygote:部分 代码缓存集合,代码= 13KB,数据= 21KB 08-07 18:01:34.558 9157-9168/com.example.tsuryohananov.voicerecorder I/zygote:代码 缓存收集,代码= 13KB,数据= 21KB 08-07 18:01:34.558 9157-9168/com.example.tsuryohananov.voicerecorder I/zygote:增加 代码缓存容量为128KB 08-07 18 :01:34.563 9157-9206/com.example.tsuryohananov.voicerecorder D/EGL_emulation: eglMakeCurrent:0xa139c420:ver 2 0 (tinfo 0xa265dad0)08-07 18:01:34.565 9157-9168/com.example.tsuryohananov.voicerecorder I/zygote:部分代码缓存收集,代码= 13KB,数据= 38KB 08-07 18:01: 34.566 9157-9168/com.example.tsuryohananov.voicerecorder I/zygote:代码缓存收集后,代码= 13KB,数据= 38KB 08-07 18:01:34.567 9157-9168/com.example.tsuryohananov.voicerecorder I/zygote:将代码缓存容量增加到256KB 08-07 18:01:34.567 9157-9168/com.example.tsuryohananov.voicerecorder I/zygote:JIT 分配72KB用于void android.widget.TextView的编译代码。 (android.content.Context, android.util.AttributeSet,int,int)08-07 18:01:34.589 9157- 9168/com.example.tsuryohananov.voicerecorder I/zygote:编译器 分配4MB编译void android.widget.TextView。(android.content.Context, android.util.AttributeSet,int,int)08-07 18: 01:34.624 9157-9206/com.example.tsuryohananov.voicerecorder D/EGL_emulation: eglMakeCurrent:0xa139c420:ver 2 0(tinfo 0xa265dad0)08-07 18:01:34.642 9157-9206/com.example.tsuryohananov。录音机 I/chatty:uid = 10093(u0_a93)RenderThread相同1行08-07 18:01:34.692 9157-9206/com.example.tsuryohananov.voicerecorder D/EGL_emulation:eglMakeCurrent:0xa139c420:ver 2 0(tinfo 0xa265dad0)08-07 18:01:34.698 9157-9206/com.example.tsuryo hananov.voicerecorder d/OpenGLRenderer: endAllActiveAnimators上0x92173c00(RippleDrawable)与手柄 0x921263f0 08-07 18:01:35.380 9157-9206/com.example.tsuryohananov.voicerecorder d/EGL_emulation: eglMakeCurrent:0xa139c420:版本2 0 (tinfo 0xa265dad0)08-07 18:01:36.248 9157-9168/com.example.tsuryohananov.voicerecorder I/zygote:完成代码缓存集合,代码= 125KB,数据= 69KB 08-07 18:01: 36.253 9157-9168/com.example.tsuryohananov.voicerecorder I/zygote:代码缓存收集后,代码= 123KB,数据= 54KB 08-07 18:01:36.934 9157-9206/com.example.tsuryohananov.voicerecorder D/EGL_emulation:eglMakeCurrent:0xa139c420:ver 2 0(tinfo 0xa265dad0)08-07 18:01:36.958 9157-9206/com.example.tsuryohananov.voicerecorder D/RenderScript HIDL适配:IRenderScriptDevice :: getService() 08-07 18:01:36.962 9157-9206/com .example.tsuryohananov.voicerecorder W/[email protected] :: Device:getService:found null hwbinder interface 08-07 18:01:36.963 9157-9206/com.example.tsuryohananov.voicerecorder D/RenderScript HIDL适配:IRenderScriptDevice :: getService() 返回0x0 08-07 18:01:36.963 9157-9206/com.example.tsuryohananov.voicerecorder D/RenderScript HIDL适配:使用回退路径。 08-07 18:01:36.975 9157-9206/com.example。tsuryohananov.voicerecorder D/RenderScript:成功查询缓存目录: /data/user_de/0/com.example.tsuryohananov.voicerecorder/code_cache 08-07 18:01:36.976 9157-9206/com.example.tsuryohananov.voicerecorder d /的renderScript:设置缓存目录: /data/user_de/0/com.example.tsuryohananov.voicerecorder/code_cache 08-07 18:01:36.985 9157-9206/com.example.tsuryohananov.voicerecorder d/EGL_emulation :eglMakeCurrent:0xa139c420:ver 2 0(tinfo 0xa265dad0)08-07 18:01:38.488 9157-9168/com.example.tsuryohananov.voicerecorder I/zygote:部分 代码缓存集合,代码= 124KB,data = 67KB 08-07 18:01:38.488 9157-9168/com.example.tsuryo hananov.voicerecorder I/zygote:代码 缓存集合,代码= 124KB,数据= 67KB 08-07 18:01:38.488 9157-9168/com.example.tsuryohananov.voicerecorder I/zygote:增加 代码缓存容量512KB

08-07 18:01:38.805 9157-9324/com.example.tsuryohananov.voicerecorder E/MediaPlayerNative:错误(1,-2147483648)

08-07 18:01:38.809 9157-9157/com.example.tsuryohananov.voicerecorder W/System.err:java.io.IOException:Prepare failed .: status = 0x1 08-07 18:01:38.810 9157-9157/com.example.tsuryohananov .voicerecorder W/System.err:at android.media.MediaPlayer._prepare(Native Method) 08-07 18:01:38.810 9157-9157/com.example.tsuryohananov.voicerecorder W/System.err:at android.media.MediaPlayer.prepare(MediaPlayer.java:1259)08-07 18:01:38.810 9157-9157/com.example.tsuryohananov.voicerecorder W/System.err:at com.example.tsuryohananov.voicerecorder .RecordsActivity $ 2.onClick(RecordsActivity.java:67) 08-07 18:01:38.810 9157-9157/com.example.tsuryohananov.voicerecorder W/System.err:at android.view.View.performClick(View。 java:6219) 08-07 18:01:38.810 9157-9157/com.example.tsuryohananov.voicerecorder W/System.err:at android.view.View $ PerformClick.run(View.java:24482)08-07 18:01:38.810 9157-9157/com.example.tsuryohananov.voicerecorder W/System.err:at android.os.Handler .handleCallback(Handler.java:769)08-07 18:01:38.810 9157-9157/com.example.tsuryohananov.voicerecorder W/System.err:at android.os.Handler.dispatchMessage(Handler.java:98 )08-07 18:01:38.810 9157-9157/com.example.tsuryohananov.voicerecorder W/System.err:at android.os.Looper.loop(Looper.java:164)08-07 18:01: 38.810 9157-9157/com.example.tsuryohananov.voicerecorder W/System.err:at android.app.ActivityThread.main(ActivityThread.java:6540)08-07 18:01:38.810 9157-9157/com。 example.tsuryohananov.voicerecorder W/System.err:at java.lang.reflect.Method.invoke(Native Method) 08-07 18:01:38.810 9157-9157/com.example.tsuryohananov.voicerecorder W/System.err:at com .android.internal.os.Zygote $ MethodAndArgsCaller.run(Zygote.java:240) 08-07 18:01:38.810 9157-9157/com.example.tsuryohananov.voicerecorder W/System.err的:在 融为一体。 android.internal.os.ZygoteInit.main(ZygoteInit。Java的:767)

+0

这样做(我认为):) –

+0

登录'filePath',看是否存在路径 – Ali

+0

尝试它现在我的手机(Xperia z5高级版)这是新的,刚进入RecordsActivity,这显示在logcat上 - 08-07 18:42:11.827 17751-17751/com.example.tsuryohananov.voicerecorder E/ExtMediaPlayer-JNI:QCMediaPlayer找不到.... 08-07 18:42:11.827 17751-17751/com.examp E/MediaPlayer-JNI:JNIMediaPlayerFactory:bIsQCMediaPlayerPresent 0 08-07 18:42:11.827 17751-17751/com.example.tsuryohananov.voicerecorder E/ExtMediaPlayer-JNI:QCMediaPlayer找不到.... –

回答

0

所以原因是: 以日期时间命名的文件,当格式是这样的:

String dateTime = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss aa", Locale.getDefault()).format(new Date()); 

在MediaPlayer变出于某种原因的错误。

所以我把它改为:

String dateTime = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss aa", Locale.getDefault()).format(new Date()); 

虽然我真的很喜欢HH:mm:ss的

0

我想你必须使用recordToPlay = MainActivity.listRecord.get(position);

+0

相同的错误 08-07 18:37:50.333 27580-27593/com.example.tsuryohananov.voicerecorder E/MediaPlayerNative:error(1,-2147483648) –

相关问题