gpt4 book ai didi

java - Android Studio - 视频应用程序崩溃 - Videoview 和 Mediaplayer - 无法播放录音

转载 作者:行者123 更新时间:2023-12-02 12:01:40 25 4
gpt4 key购买 nike

我有一个应用程序,我使用按钮通过 Intent 录制视频来启动相机。这工作正常,应用程序返回到主 Activity 。当返回到主要 Activity 时,我希望在 VideoView 中播放最后录制的视频。此时我的问题就出现了。

我尝试按照下面提供的链接上的说明进行操作,但有些内容显然不正确。

https://developer.android.com/training/camera/videobasics.html

Logcat 说我需要使用 Mediaplayer。有人可以帮我写一些代码吗?

提前致谢!

package com.example.t.videorecorder;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

static final int REQUEST_VIDEO_CAPTURE=1;



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

public void startCamera(View view){
Intent intent= new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (intent.resolveActivity(getPackageManager())!=null){
startActivityForResult(intent, REQUEST_VIDEO_CAPTURE);
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intentintent) {

VideoView vW=(VideoView)findViewById(R.id.videoView);
if (requestCode==REQUEST_VIDEO_CAPTURE && resultCode==RESULT_OK){
Uri video= intent.getData();
vW.setVideoURI(video);
}
}
}

日志猫:

11-09 12:43:12.894 27047-27047/com.example.t.videorecorder E/MediaPlayer[Native]: Unable to create media player
11-09 12:43:12.896 27047-27047/com.example.t.videorecorder W/VideoView: Unable to open content: content://media/external/video/media/33789
java.io.IOException: setDataSource failed.: status=0x80000000
at android.media.MediaPlayer.nativeSetDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1061)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1050)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1004)
at android.widget.VideoView.openVideo(VideoView.java:353)
at android.widget.VideoView.access$2200(VideoView.java:72)
at android.widget.VideoView$7.surfaceCreated(VideoView.java:664)
at android.view.SurfaceView.updateWindow(SurfaceView.java:579)
at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:238)
at android.view.View.dispatchWindowVisibilityChanged(View.java:8704)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1269)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1338)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1077)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5845)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5272)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)

最佳答案

这是包含媒体播放器的代码:

vW.setMediaController(new MediaController(this));
vW.requestFocus();
vW.start();

并在 list 中添加 READ_EXTERNAL_STORAGE 权限

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

在 android marshmallow 中,转到设置,然后转到应用程序,然后转到应用程序,并在权限中允许存储访问权限。

关于java - Android Studio - 视频应用程序崩溃 - Videoview 和 Mediaplayer - 无法播放录音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47201382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com