2012-01-10 3 views
1

내 앱에 비디오를 추가하고 싶습니다. 그러나 나는 문제가있다. 나는 안드로이드 개발자를 읽고 자바 코드의 예를 발견했다. 그러나 나는 이해하지 않는다. apk 안에 비디오를 넣는 법. 그리고 어떤 경로가 있어야합니까? 나는 비디오가 SD 카드에 있어야한다는 것을 깨달았습니다. 나는 혼란스러워. 안드로이드는 VideoView.java을 developes :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- 또는 원시 폴더 – kosa

+0

[여기에 예제가 있습니다.] (http://stackoverflow.com/a/41061887/3681880) – Suragch

답변

2

당신은/입술/원시 폴더로 원료 자원을 넣어 다음 R 클래스 을 재건하고 거기에서 그들을 얻을해야합니다.

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

발췌 :

원료/
임의 파일을 자신의 원시 형태로 저장합니다. 원시 InputStream을 사용하여 이러한 리소스를 열려면 리소스 ID (R.raw.filename)로 Resources.openRawResource()를 호출합니다.

그러나 원본 파일 이름 및 파일 계층에 대한 액세스가 필요한 경우 res/raw/대신 assets/디렉토리에 일부 리소스를 저장하는 것이 좋습니다. 애셋 내의 파일 /에는 리소스 ID가 주어지지 않으므로 AssetManager 만 사용하여 읽을 수 있습니다.