2013-12-16 181 views
7

我試圖在我的應用程序中播放視頻,並且我收到無法播放此視頻錯誤。我遇到了很多關於這個問題的線索。一旦玩家準備好了,他們就要求開始播放視頻。我也這樣做。但無法弄清楚問題所在。請在下面找到我的代碼。Android VideoView無法播放視頻錯誤特別是.mp4

public class Video extends Activity implements MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener { 

public VideoView vidPlayer; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    setup(); 
    activateVideoPlayer(); 
} 

public void setup() { 
    setContentView(R.layout.step_video);   
    vidPlayer = (VideoView) findViewById(R.id.videoPlayer); 
    String playableUrl = "http://teststreaming7v.s3.amazonaws.com/public/7515/1374782317346-beagle_puppy_howl_640x360_448_main.mp4"; 

} 

@Override 
public void onPrepared(final MediaPlayer mediaPlayer) { 
    mediaPlayer.setLooping(false); 
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
     startPlayer(); 
    videoLoaded = true; 
    mediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() { 
     // show updated information about the buffering progress 
     public void onBufferingUpdate(MediaPlayer mp, int percent) { 
      Log.d(this.getClass().getName(), "percent: " + percent); 

     } 
    }); 

    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 

     public void onCompletion(MediaPlayer mediaPlayer) { 
      progress.setProgress(100); 
        setResult(Activity.RESULT_OK); 
        finish(); 
     } 
    }); 

    readyToPlay = true; 
} 

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
} 

@Override 
public void onPause() { 
    super.onPause(); 
    pausePlayer(); 
} 

@Override 
public void finish() { 
    super.finish(); 
    overridePendingTransition(R.anim.engagement_fade_in, R.anim.engagement_fade_out); 
} 

@Override 
public void onBackPressed() { 
    isGoingBack = true; 
    setResult(Activity.RESULT_CANCELED); 
    finish(); 
} 

@Override 
public boolean onError(MediaPlayer mediaPlayer, int i, int i1) { 
    JLogger.getInstance(this).log("Video Player Error!!" + Integer.toString(i) + "/" + Integer.toString(i1)); 

    return false; 
} 

public void startPlayer() { 
    isPaused = false; 
    vidPlayer.start(); 
} 

public void pausePlayer() { 
    isPaused = true; 
     vidPlayer.pause(); 
} 

private void activateVideoPlayer() { 
    vidPlayer.setOnErrorListener(this); 
    vidPlayer.setOnPreparedListener(this); 

    btnPlay.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      if (vidPlayer.isPlaying()) { 
       pausePlayer(); 
      } else { 
       startPlayer(); 
      } 
     } 
    }); 

    vidPlayer.setVideoURI(Uri.parse(playableUrl)); 
    vidPlayer.seekTo(step.resumePosition); 
} 
} 

我正在使用的設備是Motorola Atrix - Android 4.1.2 - 解鎖。 我也試過其他設備,如Nexus 4,5和Samasung Tab 2.它的工作很好。

這是我的日誌:

12-16 13:42:35.184 4427-4427/? D/MediaPlayer﹕ Couldn't open file on client side,trying server side 
12-16 13:42:35.184 1417-1830/? I/AwesomePlayer﹕ setDataSource_l('http://teststreaming7v.s3.amazonaws.com/public/7515/1374782317346-beagle_puppy_howl_640x360_448_main.mp4') 
12-16 13:42:35.184 1417-5481/? V/ChromiumHTTPDataSource﹕ connect on behalf of uid 10069 
12-16 13:42:35.184 1417-5481/? I/ChromiumHTTPDataSource﹕ connect to http://teststreaming7v.s3.amazonaws.com/public/7515/1374782317346-beagle_puppy_howl_640x360_448_main.mp4 @0 
12-16 13:42:35.684 1424-1673/? I/﹕ odm_disp_esd_thread is running(467) state=1 
12-16 13:42:35.684 1417-5481/? W/WVMExtractor﹕ Failed to open libwvm.so 
12-16 13:42:36.184 4547-4576/? W/GAV2﹕ Thread[GAThread,5,main]: Exception sending hit: HttpHostConnectException 
12-16 13:42:36.184 4547-4576/? W/GAV2﹕ Thread[GAThread,5,main]: Connection to https://ssl.google-analytics.com refused 
12-16 13:42:36.184 1417-5481/? E/OMXCodec﹕ failed to allocate node OMX.Nvidia.h264.decode 
12-16 13:42:36.184 1417-5481/? E/OMXCodec﹕ failed to allocate node OMX.google.h264.decode 
12-16 13:42:36.184 1417-5481/? I/OMXCodec﹕ [OMX.google.h264.decoder] AVC profile = 77 (Main), level = 22 
12-16 13:42:36.184 1417-5481/? I/OMXCodec﹕ [OMX.google.h264.decoder] video dimensions are 320 x 240 
12-16 13:42:36.184 1417-5481/? I/OMXCodec﹕ [OMX.google.h264.decoder] Crop rect is 320 x 240 @ (0, 0) 
12-16 13:42:37.184 4427-4427/? D/MediaPlayer﹕ getMetadata 
12-16 13:42:37.184 4427-4427/? D/VideoSample﹕ onPrepared() method 
12-16 13:42:37.184 1417-1687/? D/AudioHardwareMot﹕ bufSize = 8192 
12-16 13:42:37.184 1417-5484/? E/SoftAVC﹕ Decoder failed: -2 
12-16 13:42:37.184 1417-5485/? E/OMXCodec﹕ [OMX.google.h264.decoder] ERROR(0x80001001, -1007) 
12-16 13:42:37.184 1417-5486/? I/SoftAAC2﹕ Reconfiguring decoder: 44100 Hz, 2 channels 
12-16 13:42:37.184 4427-4449/? E/MediaPlayer﹕ error (1, -2147483648) 
12-16 13:42:37.184 1692-2165/? D/dalvikvm﹕ GC_EXPLICIT freed 113K, 39% free 8906K/14467K, paused 3ms+5ms, total 93ms 
12-16 13:42:37.184 4427-4427/? E/MediaPlayer﹕ start called in state 0 
12-16 13:42:37.184 4427-4427/? E/MediaPlayer﹕ error (-38, 0) 
12-16 13:42:37.184 4427-4427/? E/MediaPlayer﹕ Error (1,-2147483648) 
12-16 13:42:37.184 4427-4427/? D/VideoView﹕ Error: 1,-2147483648 
12-16 13:42:37.184 4427-4427/? D/VideoSample﹕ VideoSample: Video Player Error!!1/-2147483648 
12-16 13:42:37.184 4427-4427/? D/VideoSample﹕ VideoSample: Get url: http://teststreaming7v.s3.amazonaws.com/public/7515/1374782317346-beagle_puppy_howl_640x360_448_main.mp4 
12-16 13:42:37.184 4427-4427/? E/MediaPlayer﹕ Error (-38,0) 
12-16 13:42:37.184 4427-4427/? D/VideoView﹕ Error: -38,0 
12-16 13:42:37.184 4427-4427/? D/VideoSample﹕ VideoSample: Video Player Error!!-38/0 
12-16 13:42:37.184 4427-4427/? D/VideoSample﹕ VideoSample: Get url: http://teststreaming7v.s3.amazonaws.com/public/7515/1374782317346-beagle_puppy_howl_640x360_448_main.mp4` 

編輯1

我試着打了以下兩個.mp4文件出其第一個戲劇和第二的則沒有。

視頻1屬性
URL:Video URL
視頻比特率:179.9千位/秒
音頻信道:立體聲

Video1

視頻2個屬性 網址:Video URL
視頻比特率:446.9千比特/秒
音頻通道:單聲道

Video2

+0

可能是因爲moov原子不在文件的開頭 – njzk2

+0

@ njzk2是否影響在其他設備如nexus 4或5或三星平板電腦中播放相同的視頻?我不熟悉moov原子和其他相關主題。對不起,如果我提出愚蠢的錯誤問題。我的第二個視頻不能在摩托羅拉Atrix和LG Optimus上播放。這些是我檢查過的設備。 – Uma

+0

不完全確定,但你的觀點確實有道理。 – njzk2

回答

8

問題在於第二個視頻不在H.264 AVC Baseline配置文件中。

+0

謝謝,通過了解這一點,我可以用這個gstreamer管道生成這樣一個mp4視頻:'gst-launch-0.10 -e videotestsrc num-buffers = 1000! x264enc qp-min = 18! video/x-h264,stream-format = avc,profile = constrained-baseline! qtmux! filesink location = test.mp4' – jcarballo

2

我知道誰只是有這個問題,也與MP4視頻,問題不在代碼上,它是在視頻本身,關於幀數/秒,嘗試其他視頻,你知道的是完美的

+0

我以前從未使用過videoview,所以你可能想看看這些命題:http://stackoverflow.com/questions/17399351/how-to-play-mp4-video-in-videoview-in-android –

+0

問題與視頻編碼。感謝您的投光燈。 – Uma