gpt4 book ai didi

android - Android编程如何在App启动时添加视频文件?

转载 作者:行者123 更新时间:2023-11-29 22:22:51 24 4
gpt4 key购买 nike

每当我启动显示详细信息的应用程序时,我都需要添加视频文件。所以我需要帮助。我需要知道如何为此编写代码。

最佳答案

将您的视频文件保存在raw 文件夹中

输入你的视频文件名

path="android.resource://yourpackagename/"+R.raw.yourvideofilename;

看下面的类

public class HomeVideo extends Activity{
private VideoView videoView;
String extStorageDirectory;
protected static final int PLAY = 0x101;
protected static final int STOP = 0x102;
protected static final int PAUSE = 0x103;
int State;
private String current;

private String path ;
private VideoView mVideoView;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.homevideo);
path="android.resource://yourpackagename/"+R.raw.yourvideofilename;
mVideoView = (VideoView) findViewById(R.id.video);
if (path == null || path.length() == 0) {
Toast.makeText(HomeVideo.this, "File URL/path is empty",
Toast.LENGTH_LONG).show();

} else {
// If the path has not changed, just start the media player
if (path.equals(current) && mVideoView != null) {
mVideoView.start();
mVideoView.requestFocus();
return;
}
current = path;
mVideoView.setVideoPath(path);
mVideoView.start();
mVideoView.requestFocus();
}
mVideoView.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer arg0) {

Intent in =new Intent(HomeVideo.this,NextActivity.class);
startActivity(in);
finish();
}
});
}

}

xml 像这样的文件

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView
android:id="@+id/video"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:keepScreenOn="true">
</VideoView>
</LinearLayout>

在 list 文件中

 <activity android:name=".HomeVideo" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>

关于android - Android编程如何在App启动时添加视频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6689643/

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