gpt4 book ai didi

android - 尝试在Android上播放视频时出现Resources $ NotFoundException?

转载 作者:行者123 更新时间:2023-12-03 17:42:03 26 4
gpt4 key购买 nike

E/AndroidRuntime( 5751): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.Android/com.example.Android.OpenByApiActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030001

E/AndroidRuntime( 5751): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)

E/AndroidRuntime( 5751): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)

E/AndroidRuntime( 5751): at android.app.ActivityThread.access$1500(ActivityThread.java:117)

E/AndroidRuntime( 5751): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)

E/AndroidRuntime( 5751): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030001



有人知道为什么会这样吗?这是我的视频和xml代码
public class OpenByApiActivity extends Activity implements Callback {


MediaPlayer mp = new MediaPlayer();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.video);
StringBuilder log = new StringBuilder();
String[] clearLogcat = new String[] { "logcat", "-c",};
try {
Runtime.getRuntime().exec(clearLogcat);
}
catch (IOException e) {
e.printStackTrace();
}
File location = new File("/sdcard/MediaTestFiles/sample.mp4");
Uri path = Uri.fromFile(location);
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.surfaceview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setFixedSize(176, 144);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDisplay(surfaceHolder);
mp= MediaPlayer.create(this, path);
if(mp!=null){
mp.start();
}}}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub

}

@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub

}}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>

<SurfaceView
android:id="@+id/surfaceview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

最佳答案

您可以尝试一下并告诉我是否仍然存在相同的问题吗?

final File location = new File(Environment.getExternalStorageDirectory(), "/MediaTestFiles/sample.mp4");

我想问题可能出在您的路径上。

更新

你能移动这条线吗
@Override
public void surfaceCreated(SurfaceHolder arg0) {
//mp.setDisplay(surfaceHolder);
mp.setDisplay(arg0);
}

在onSurfaceCreated内部。

关于android - 尝试在Android上播放视频时出现Resources $ NotFoundException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7225151/

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