5

我有一个简单的应用程序,它以在 VideoView 中播放 mp4 视频的启动屏幕活动开始。视频完成后,我正在尝试通过 OnCompletionListener 开始一个新活动。

当我启动应用程序时,视频完美运行;按预期播放声音和音频。视频播放完毕后,应用程序会显示一个标题为“无法播放视频”的对话框,并在按下“确定”按钮后正常继续。当我将音频添加到使用 Adob​​e After Effects 创建的 mp4 时,似乎只会出现此问题。我使用了完全相同的视频减去音轨,它不会抛出这个错误。我假设文件的编码很好,因为它在显示对话框之前完全播放。

这是我的代码:

public class Splash extends Activity {


 @Override  
 public void onCreate(Bundle savedInstanceState) {  

     super.onCreate(savedInstanceState);
     setContentView(R.layout.splash);

     Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.audio_intro); 

     VideoView videoview = (VideoView) findViewById(R.id.splash_view);
     videoview.setKeepScreenOn(true);  
     videoview.setVideoURI(video);

     videoview.setOnCompletionListener(new OnCompletionListener() {  
           public void onCompletion(MediaPlayer mp) {  
                 Intent intent = new Intent(Splash.this, Menu.class);
                 startActivity(intent);
                 finish();
           }
     });

     videoview.requestFocus();
     videoview.start();
 }

}

这是 LogCat 显示的内容:

06-30 14:49:33.095: V/MediaPlayer-JNI(21544): native_setup
06-30 14:49:33.095: V/MediaPlayer(21544): constructor
06-30 14:49:33.095: V/MediaPlayer(21544): setListener
06-30 14:49:33.095: I/MediaPlayer(21544): path is null
06-30 14:49:33.095: V/MediaPlayer-JNI(21544): setDataSourceFD: fd 54
06-30 14:49:33.095: V/MediaPlayer(21544): setDataSource(54, 2521, 173889)
06-30 14:49:33.110: V/MediaPlayer(21544): setVideoSurfaceTexture
06-30 14:49:33.110: V/MediaPlayer-JNI(21544): setAudioStreamType: 3
06-30 14:49:33.110: V/MediaPlayer(21544): MediaPlayer::setAudioStreamType
06-30 14:49:33.110: V/MediaPlayer(21544): setVideoSurfaceTexture
06-30 14:49:33.110: V/MediaPlayer(21544): prepareAsync
06-30 14:49:33.140: V/MediaPlayer(21544): message received msg=5, ext1=480, ext2=270
06-30 14:49:33.140: V/MediaPlayer(21544): New video size 480 x 270
06-30 14:49:33.140: V/MediaPlayer(21544): callback application
06-30 14:49:33.140: V/MediaPlayer(21544): back from callback
06-30 14:49:33.140: V/MediaPlayer(21544): message received msg=1, ext1=0, ext2=0
06-30 14:49:33.140: V/MediaPlayer(21544): prepared
06-30 14:49:33.140: V/MediaPlayer(21544): callback application
06-30 14:49:33.140: V/MediaPlayer(21544): back from callback
06-30 14:49:33.145: I/MediaPlayer(21544): mOnVideoSizeChangedListener. Send MEDIA_SET_VIDEO_SIZE message.
06-30 14:49:33.145: V/MediaPlayer(21544): getVideoWidth
06-30 14:49:33.145: V/MediaPlayer-JNI(21544): getVideoWidth: 480
06-30 14:49:33.145: V/MediaPlayer(21544): getVideoHeight
06-30 14:49:33.145: V/MediaPlayer-JNI(21544): getVideoHeight: 270
06-30 14:49:33.145: I/MediaPlayer(21544): mOnPreparedListener. Send MEDIA_PREPARED message.
06-30 14:49:33.145: D/MediaPlayer(21544): getMetadata
06-30 14:49:33.145: V/MediaPlayer(21544): getVideoWidth
06-30 14:49:33.145: V/MediaPlayer-JNI(21544): getVideoWidth: 480
06-30 14:49:33.145: V/MediaPlayer(21544): getVideoHeight
06-30 14:49:33.145: V/MediaPlayer-JNI(21544): getVideoHeight: 270
06-30 14:49:33.170: I/MediaPlayer(21544): sendBroadcast android.media.IMediaPlayer.videoexist
06-30 14:49:33.170: V/MediaPlayer-JNI(21544): start
06-30 14:49:33.170: V/MediaPlayer(21544): start
06-30 14:49:37.915: V/MediaPlayer(21544): message received msg=100, ext1=1, ext2=-1007
06-30 14:49:37.915: E/MediaPlayer(21544): error (1, -1007)
06-30 14:49:37.915: V/MediaPlayer(21544): callback application
06-30 14:49:37.915: V/MediaPlayer(21544): back from callback
06-30 14:49:37.915: E/MediaPlayer(21544): Error (1,-1007)
06-30 14:49:37.915: D/VideoView(21544): Error: 1,-1007

我希望有人可以帮助我,因为我已经尝试了很多方法来解决这个问题,但似乎在任何地方都找不到类似的问题被提及/解决。谢谢。

4

3 回答 3

4

只是一个想法:我建议尝试使用视频转换器将视频转换,例如http://www.wondershare.com/pro/media-converter.html,(从 mp4)再次转换为 mp4,以确保您将音频(和视频)获取到 Android 支持的标准,如http://developer.android.com/guide/appendix/media-formats.html#core中所列。

于 2012-06-30T14:27:12.177 回答
1

另一个随机猜测,在完成侦听器中完成您的活动之前调用 videoview.stopPlayback :)

编辑:对话框出现在您的完成侦听器之前还是之后?

于 2012-06-30T14:43:05.877 回答
1

(1, -1007) 错误表示:MEDIA_ERROR_UNKNOWN - “文件或网络相关的操作错误。”

这可能来自损坏的文件

另请参阅 android.media.MediaPlayer.OnErrorListener#onError http://developer.android.com/reference/android/media/MediaPlayer.OnErrorListener.html#onError的 javadoc

@param what the type of error that has occurred:
MEDIA_ERROR_UNKNOWN
MEDIA_ERROR_SERVER_DIED

@param extra an extra code, specific to the error. Typically implementation dependent.
MEDIA_ERROR_IO
MEDIA_ERROR_MALFORMED
MEDIA_ERROR_UNSUPPORTED
MEDIA_ERROR_TIMED_OUT
于 2014-03-12T18:00:38.267 回答