我正在尝试在我的应用程序中播放视频,但我得不能播放此视频错误.关于这一点,我遇到了很多线索.他们要求在玩家准备好后开始播放视频.我也是这样做的.但无法弄清楚问题.请在下面找到我的代码.
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); } }
我正在使用的设备是摩托罗拉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,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文件,其中第一个播放,第二个播放.
解决方法
问题是第二个视频不在H.264 AVC Baseline配置文件中.