Android — Can't play any videos (mp4/mov/3gp/etc.)?

前端 未结 3 1123
旧时难觅i
旧时难觅i 2020-12-03 06:16

I\'m having great difficulty getting my Android application to play videos from the SD card. It doesn\'t matter what size, bitrate, video format, or any other setting I can

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 07:07

    I have had quite a bit of trouble getting many different videos to play on my phone (HTC hero). Standard 512K mp4's play (example: http://www.archive.org/details/more_animation), check with them first to make sure it's not your code.

    Here's my code, from onCreate() in a sub-activity which only plays the video file:

    
    
    
        protected VideoView mine;
        protected boolean done = false;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.videoshow);  
            mine = (VideoView) findViewById(R.id.video);   // Save the VideoView for touch event processing 
            try {
                String myURI = "/sdcard/" + path + "/v/" 
                              + currentItem.getFile() 
                              + "." + currentItem.getFileType();
                Uri video = Uri.parse(myURI); 
                mine.setVideoURI(video);
                mine.start();
                mine.setOnCompletionListener(new OnCompletionListener() {
    
                    public void onCompletion(MediaPlayer mp) {  
                        result.putExtra("com.ejf.convincer01.Finished", true);
                        done = true;
                    }
                });
            } catch (Exception ex) {
                Log.d(DEBUG_TAG, "Video failed: '" + ex + "'" );
            }
    

提交回复
热议问题