2011-05-16 5 views
0

비디오를 재생하기 위해 현재 코드에 추가해야하는 특정 코드가 무엇인지 말해 줄 수 있습니까?"비디오보기"버튼을 클릭 한 후 비디오를 재생하는 방법?

public class ViewVideo extends Activity { 
     private String filename; 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      Bundle extras = getIntent().getExtras(); 
      filename = extras.getString("videoPath"); 

      VideoView viewVideo = new VideoView(this); 
      setContentView(viewVideo); 
      viewVideo.setVideoPath(filename); 
      viewVideo.setMediaController(new MediaController(this)); 
      viewVideo.requestFocus(); 
      viewVideo.start(); 

     } 
} 

답변

1

안드로이드의 미디어 파일을 재생하는 방법보다가 ..

이 하나를 시도해보십시오 :

public void videoPlayer(String path, String fileName, boolean autoplay){ 

    getWindow().setFormat(PixelFormat.TRANSLUCENT); 

     VideoView videoHolder = new VideoView(this); 

     videoHolder.setMediaController(new MediaController(this)); 

     videoHolder.setVideoURI(Uri.parse(path+"/"+fileName)); 

     videoHolder.requestFocus(); 


     if(autoplay){ 

       videoHolder.start(); 

     } 
} 

난이 도움이되기를 바랍니다 ..

+0

그래서 내가 ViewVideo.class에이 코드를 넣어해야 당신에게 도움이 될 것입니다 생각이 코드를보십시오 .. 당신을 도와줍니다? – misery

+0

경로, 파일 이름 및 자동 재생과 같은 인수를 전달하여이 메소드를 호출합니다.이 메서드는 onCreate (savedInstanceState 번들) 뒤에 넣을 수 있습니다. – CMA

0

이 시도 .. .

public void videoPlayer(String path, String fileName, boolean autoplay){ 
    //get current window information, and set format, set it up differently, if you need some special effects 
    getWindow().setFormat(PixelFormat.TRANSLUCENT); 
    //the VideoView will hold the video 
    VideoView videoHolder = new VideoView(this); 
    //MediaController is the ui control howering above the video (just like in the default youtube player). 
    videoHolder.setMediaController(new MediaController(this)); 
    //assing a video file to the video holder 
    videoHolder.setVideoURI(Uri.parse(path+"/"+fileName)); 
    //get focus, before playing the video. 
    videoHolder.requestFocus(); 
    if(autoplay){ 
     videoHolder.start(); 
    } 

    } 

이 방법을 호출하십시오. 버튼을 클릭하면 필요한 인수 (비디오 파일 경로, 파일 이름, 자동 재생)가 전달됩니다.

희망이

0

내가이

package com.VideoPlayer; 

import android.app.Activity; 
import android.media.*; 
import android.os.Bundle; 
import android.widget.*; 
import android.view.*; 

public class myPlayer extends Activity implements View.OnClickListener { 
    /** Called when the activity is first created. */ 
    Button play,stop,sd; 
    MediaPlayer mp; 
    String path; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     play=(Button)findViewById(R.id.play); 
     stop=(Button)findViewById(R.id.stop); 
     sd=(Button)findViewById(R.id.sd); 
     play.setOnClickListener(this); 
     stop.setOnClickListener(this); 
     sd.setOnClickListener(this); 
     //mp=MediaPlayer.create(this, R.raw.sample); 
    } 
    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     if(v==play) 
     { 
      if(mp.isPlaying()==false && mp!=null) 
      { 

         mp.start(); 
      } 
     } 
     if(v==stop) 
     { 
      mp.stop(); 
      mp.release(); 
      mp=null; 
     } 
     if(v==sd) 
     { 
      path="/sdcard/sample.mp4"; 
      try{ 
      mp=new MediaPlayer(); 
      mp.setDataSource(path); 
      mp.prepare(); 
      mp.start(); 
      } 
      catch(Exception e) 
      { 
       Toast.makeText(this,e.toString(),Toast.LENGTH_LONG) 
       .show(); 
      } 
     } 

    } 
} 
+0

@ user755060 viewVideo 활동이 끝난 후 어떻게해야합니까? 동영상의 동영상 재생이 끝났습니까? 위에 수정 됨 – misery

관련 문제