2011-01-29 16 views
0

我正在做多媒體應用程序。我嘗試了幾個不同的例子來實現在視圖中的視圖,但我無法得到。我可以聽到聲音,但沒有視覺出現。有沒有可能從視圖中獲取視頻。我的目標SDK是2.2 API級別8.即使我安裝了我的apk到移動設備,仍然沒有任何改變。請指導我。如何在Surface視圖中訪問視頻

回答

0

我不確定你想如何播放你的視頻,將它流式傳輸或複製到你的SD卡或/ res文件夾,但我有以下播放視頻。我可以選擇是否流或將其從一個文件夾在我的SD卡播放

Video.java

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.VideoView; 

public class Movie extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 


     setContentView(R.layout.video_layout); 
     VideoView video = (VideoView) findViewById(R.id.movie); 

     //this is the place where you define where to get the video from (this can be from your sd or a stream) 
     video.setVideoPath(
     "/sdcard/video/videofile.mp4" 

     /*"rtsp://Youtube Stream*/ 
       ); 

     //after the video is loaded it will then start 
     video.start(); 
    } 
} 

video_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <VideoView 
     android:id="@+id/movie" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center"> 
    </VideoView>  
</FrameLayout> 

希望這將幫助你! 我也有SurfaceView的幾個問題,但這樣我的問題就解決了。

+0

如果此答案有幫助,請標記爲已回答。否則我們可以找到另一個解 – SterAllures 2011-01-31 15:55:11