2011-08-03 7 views
0

ディレクトリの文字列でコードを再生しようとしましたが、ルートを削除するか、ディレクトリ文字列でFを追加するようにしました:/ しかし、 。私のアンドロイド携帯電話のエラーを取得しているIm "ビデオを再生できません" それの下に "申し訳ありません、このビデオは再生することはできません。Androidでmp4ビデオファイルを再生しようとしています

私はアンドロイドにいくつかの.3gpの動画を持っていますので、私のPC上のプログラムで.mp4に変換しましたが、まだこのエラーが表示されています。

これは助けを

package com.lightcone.playingvideo; 

    import java.io.File; 

    import android.app.Activity; 
    import android.media.MediaPlayer; 
    import android.media.MediaPlayer.OnCompletionListener; 
    import android.media.MediaPlayer.OnPreparedListener; 
    import android.os.Bundle; 
    import android.os.Environment; 
    import android.view.MotionEvent; 
    import android.widget.VideoView; 

    public class PlayingVideo extends Activity implements OnCompletionListener, OnPreparedListener { 

     static private final String pathToFile = "DCIM/100MEDIA/VIDEO0030.mp4"; // Video source file 
     private VideoView videoPlayer; 

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

     // Find the root of the external storage file system. We assume the file system is 
     // mounted and writable (see the project WriteSDCard for ways to check this). 

     File root = Environment.getExternalStorageDirectory(); 

     // Assign a VideoView object to the video player and set its properties. It 
     // will be started by the onPrepared(MediaPlayer vp) callback below when the 
     // file is ready to play. 

     videoPlayer = (VideoView) findViewById(R.id.videoPlayer); 
     videoPlayer.setOnPreparedListener(this); 
     videoPlayer.setOnCompletionListener(this); 
     videoPlayer.setKeepScreenOn(true);  
     videoPlayer.setVideoPath(root + "/" + pathToFile); 
     } 

     /** This callback will be invoked when the file is ready to play */ 
     @Override 
     public void onPrepared(MediaPlayer vp) { 

     // Don't start until ready to play. The arg of seekTo(arg) is the start point in 
     // milliseconds from the beginning. In this example we start playing 1/5 of 
     // the way through the video if the player can do forward seeks on the video. 

     if(videoPlayer.canSeekForward()) videoPlayer.seekTo(videoPlayer.getDuration()/5); 
     videoPlayer.start(); 
     } 

     /** This callback will be invoked when the file is finished playing */ 
     @Override 
     public void onCompletion(MediaPlayer mp) { 
     // Statements to be executed when the video finishes. 
     this.finish(); 
     } 

     /** Use screen touches to toggle the video between playing and paused. */ 
     @Override 
     public boolean onTouchEvent (MotionEvent ev){ 
     if(ev.getAction() == MotionEvent.ACTION_DOWN){ 
      if(videoPlayer.isPlaying()){ 
        videoPlayer.pause(); 
      } else { 
        videoPlayer.start(); 
      } 
      return true;   
     } else { 
      return false; 
     } 
     } 
    } 

おかげコードです。

答えて

0

MP4は単なるビデオコンテナであり、すべての種類のフォーマットを含むことができます。

携帯電話のハードウェアデコーダがサポートしているビデオの種類(H264メインプロファイルまたはベースプロファイルなど)を知る必要があります。また、一部のハードウェアデコーダでは、ビットレートとビデオ解像度に制限があることに注意してください。

あなたのデバイスにネイティブビデオプレーヤーがある場合は、ファイルの最適なテストは、ネイティブプレーヤーで再生しようとすることです。その場合、あなたのアプローチでも同様の可能性があります。

関連する問題