2010-07-02 76 views
1

我想要做的是播放從外部SD卡檢索到的第一個視頻,這在我的T-Mobile G2原來是樣本視頻爲手機。現在我認爲,因爲它在手機視頻播放器中播放,因此在我的測試應用程序中播放VideoView時沒有問題。Android VideoView不能在T-Mobile G2上播放示例視頻(只是音頻)

錯誤如何...

我得到的只是音頻播放。我很確定代碼都很好。畢竟這很簡單。

我能想到的是,也許手機視頻播放器使用一些原生播放功能,支持更多的視頻格式?

我也試過從本網站http://support.apple.com/kb/HT1425播放mv4(實際上是一個MP4文件)和3gp文件,但將它們推向模擬器SDCard,但都表現出同樣的問題。音頻但沒有視頻!

其實,我是否在某處丟失了許可?

其他人能解釋這種行爲嗎?

代碼:

public class Video extends Activity { 

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

     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
           WindowManager.LayoutParams.FLAG_FULLSCREEN); 

     setContentView(R.layout.video); 

     // Get the external storage state 
     String state = Environment.getExternalStorageState(); 

     // Check if we can read it in 
     if (Environment.MEDIA_MOUNTED.equals(state)==false&& 
     Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)==false) 
     { 
     // We can't read from the memory card, so warn and return; 
     Toast toast = Toast.makeText(this, 
      "The SD card is either missing or not in a readable state.", Toast.LENGTH_LONG); 
     toast.show(); 
     return; 
     } 

     // Get a cursor to the video files 
     Cursor cc = this.getContentResolver().query(
      MediaStore.Video.Media.EXTERNAL_CONTENT_URI, 
      null, null, null, null); 

     // Get the video column index 
     int videoIDColumn = cc.getColumnIndex(MediaStore.Video.VideoColumns._ID); 

     // Iterate though the videos pointed to by the cursor 
     if (cc.moveToFirst()) 
     { 
      int videoID = cc.getInt(videoIDColumn); 
      Uri videoPath = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,String.valueOf(videoID)); 

      // Log and add an image to the view 
      Log.i("Video Found",videoPath.toString()); 

      VideoView videoView = (VideoView)findViewById(R.id.VideoTest); 
      videoView.setVideoURI(videoPath); 
      videoView.start(); 
     } 
     else 
     { 
     Toast toast = Toast.makeText(this, 
      "Can't find a video to play.", Toast.LENGTH_LONG); 
     toast.show(); 
     } 
    } 
} 

在先進的感謝!

安迪

**更新

我採用了android 1.5和1.6,問題仍然存在嘗試。

而且,剛纔檢查logcat的,我沒有得到任何錯誤,任何其他文件,但對於名爲.3gp我得到下面這個錯誤:

07-02 10:53:31.181: INFO/Video Found(235): content://media/external/video/media/2 
07-02 10:53:31.383: VERBOSE/VideoView(235): reset duration to -1 in openVideo 
07-02 10:53:31.541: INFO/ActivityManager(58): Displayed activity com.dvl.testing/.screens.Video: 533 ms (total 533 ms) 
07-02 10:53:31.693: WARN/PlayerDriver(31): Using generic video MIO 
07-02 10:53:31.883: ERROR/SW_DEC(31): PV SW DECODER is used for MPEG4 
07-02 10:53:31.922: DEBUG/AudioSink(31): bufferCount (4) is too small and increased to 12 
07-02 10:53:32.322: INFO/ARMAssembler(58): generated scanline__00000077:03010104_00000004_00000000 [ 22 ipp] (41 ins) at [0x2166f8:0x21679c] in 3379159 ns 

意義的人?

回答

5

哇,有時我討厭android文檔。

原來,在我的情況下,我是爲xml中的VideoView指定一個背景顏色,但不是我認爲在視頻加載/緩衝時顯示的背景顏色,而是實際上是前景色,在完全背後播放的視頻中渲染!笑

因此改變:

<VideoView 
    android:id="@+id/VideoTest" 
    android:background="#FF00FF00" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
</VideoView> 

<VideoView 
    android:id="@+id/VideoTest" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
</VideoView> 

作品一種享受,我現在我的影片都呈現! :)

希望這可以幫助別人!

Andy。

相關問題