2011-01-29 12 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