gpt4 book ai didi

java - 如何将视频放入apk中?

转载 作者:行者123 更新时间:2023-11-30 09:41:57 25 4
gpt4 key购买 nike

我想在我的应用中添加视频。但我有一个问题。我阅读了 android 开发人员并找到了 java 代码的示例。但我不明白。如何将视频放入 apk 中。应该走什么路?我意识到视频应该在 SD 卡上,不是吗?。我很困惑 。Android开发VideoView.java:

/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.apis.media;

import com.example.android.apis.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

public class VideoViewDemo extends Activity {

/**
* TODO: Set the path variable to a streaming video URL or a local media
* file path.
*/
private String path = "";
private VideoView mVideoView;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
mVideoView = (VideoView) findViewById(R.id.surface_view);

if (path == "") {
// Tell the user to provide a media file URL/path.
Toast.makeText(
VideoViewDemo.this,
"Please edit VideoViewDemo Activity, and set path"
+ " variable to your media file URL/path",
Toast.LENGTH_LONG).show();

} else {

/*
* Alternatively,for streaming media you can use
* mVideoView.setVideoURI(Uri.parse(URLstring));
*/
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();

}
}
}

最佳答案

您应该将原始资源放入/res/raw 文件夹,然后重建您的 R 类并从那里得到它们。

http://developer.android.com/guide/topics/resources/providing-resources.html

节选:

原始/
以原始形式保存的任意文件。要使用原始 InputStream 打开这些资源,请使用资源 ID(即 R.raw.filename)调用 Resources.openRawResource()。

但是,如果您需要访问原始文件名和文件层次结构,您可以考虑将一些资源保存在 assets/目录中(而不是 res/raw/)。 assets/中的文件没有资源 ID,因此您只能使用 AssetManager 读取它们。

关于java - 如何将视频放入apk中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8805743/

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