2012-01-10 9 views
1

私のアプリにビデオを追加したいと思います。しかし、私は問題があります。私はアンドロイドの開発者を読んで、Javaコードの例を見つけました。しかし、私は理解していません。 apkの中にビデオを入れる方法。どのような道があるべきですか?私はビデオがSDカードでなければならないことに気づいた、それは?よくわかりません 。 アンドロイドはVideoView.javaを発達さ:apkの中にビデオを入れる方法は?

/* 
* 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(); 

     } 
    } 
} 
+0

あなたは資産フォルダの中にビデオを置くことができます – sebataz

+0

ここでは議論が役に立つかもしれませんhttp://stackoverflow.com/questions/3028717/how-to-play-videos-in-android-from-assets-folder- or-raw-folder – kosa

+0

[これは例です。](http://stackoverflow.com/a/41061887/3681880) – Suragch

答えて

2

あなたは/ resを/生フォルダにあなたの生のリソースを配置し、あなたのRクラス を再構築し、そこからそれらを取得する必要があります。

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

抜粋:

生/
任意のファイルは、彼らの生の形式で保存します。未処理のInputStreamでこれらのリソースを開くには、リソースID(R.raw.filename)を使用してResources.openRawResource()を呼び出します。

ただし、元のファイル名とファイル階層にアクセスする必要がある場合は、リソースをres/raw /の代わりにassets /ディレクトリに保存することを検討することもできます。アセットファイル/はリソースIDが与えられていないため、AssetManagerを使用して読み取ることができます。

関連する問題