单击列表项时播放视频

时间:2012-02-23 21:40:05

标签: android video view

我为我正在制作的应用创建了几个主题的列表,但我需要它,所以当用户点击列表项时,它会打开视频

我有

public class Intro extends ListActivity {

String classes[] = { "Name", "Age", "From", "Feeling"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setListAdapter(new ArrayAdapter<String>(Intro.this,
            android.R.layout.simple_list_item_1, classes));
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String cheese = classes[position];
    try {
        Class ourClass = Class.forName("com.IrishSign.app." + cheese);
        Intent ourIntent = new Intent(Intro.this, ourClass);
        startActivity(ourIntent);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

}

public class Age extends Activity  
{  
    private VideoView vView;  

    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState)  
    {  
       //sets the Bundle  
       super.onCreate(savedInstanceState);  
       //sets the context  
       setContentView(R.layout.main);  

       //get the VideoView from the layout file  
       vView = (VideoView)findViewById(R.id.vidview1);  

       //use this to get touch events  
       vView.requestFocus(); }

       private String vSource;  

       public void onCreate1(Bundle savedInstanceState)  
       {  
        //...  

        //replace line 23 with these lines of code  
        //loads video from the Resources folder  
        //set the video path  
        vSource ="android.resource://com.IrishSign.app/" + R.raw.age;  
        //set the video URI, passing the vSourse as a URI  
        vView.setVideoURI(Uri.parse(vSource));  

        //...  
        }  
{

    //enable this if you want to enable video controllers, such as pause and forward  
    vView.setMediaController(new MediaController(this));  

    //plays the movie  
    vView.start();  
} 

}

当我调试应用时,我得到未找到来源。 你有什么问题吗?

0 个答案:

没有答案