2011-01-27 83 views
0

嗨 我想在Android手機中播放.3GP視頻文件。我想下面的代碼,但它顯示着玩video.so請告訴我,我會做什麼如何玩.3GP視頻文件在android

這是我的代碼

public class VideoPlay extends Activity { 

private String path ; 
private VideoView mVideoView; 

@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.videoplay); 
    path="http://www.boodang.com/api/videobb/101009_Pure.3gp"; 
    mVideoView = (VideoView) findViewById(R.id.video); 

    if (path == "") { 
     // Tell the user to provide a media file URL/path. 
     Toast.makeText(
       VideoPlay.this, 
       "Please edit VideoViewDemo Activity, and set path" 
         + " variable to your media file URL/path", 
       Toast.LENGTH_LONG).show(); 

    } else { 

     /* 
     * Alternatively,for streaming media you can use 
     * mVideoView.setVideoURI(Uri.parse(URLstring)); 
     */ 
     mVideoView.setVideoPath(path); 
     mVideoView.setMediaController(new MediaController(this)); 
     mVideoView.requestFocus(); 

    } 
} 
} 

的XML佈局

<?xml version="1.0" encoding="utf-8"?> 
    <FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <VideoView 
    android:id="@+id/video" 
    android:layout_width="320px" 
    android:layout_height="240px"> 
    </VideoView> 
    </FrameLayout> 

回答

2

檢查下面的代碼是沒有在Android SDK演示

package com.example.android.apis.media; 

import com.example.android.apis.R; 

import android.app.Activity; 

import android.os.Bundle; 

import android.widget.MediaController; 

import android.widget.Toast; 

import android.widget.VideoView; 

public class VideoViewDemo extends Activity { 

    /** 
    * TODO: Set the path variable to a streaming video URL or a local media 
    * file path. 
    */ 
    private String path = ""; 
    private VideoView mVideoView; 

    @Override 
    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
     setContentView(R.layout.videoview); 
     mVideoView = (VideoView) findViewById(R.id.surface_view); 

     if (path == "") { 
      // Tell the user to provide a media file URL/path. 
      Toast.makeText(
        VideoViewDemo.this, 
        "Please edit VideoViewDemo Activity, and set path" 
          + " variable to your media file URL/path", 
        Toast.LENGTH_LONG).show(); 

     } else { 

      /* 
      * Alternatively,for streaming media you can use 
      * mVideoView.setVideoURI(Uri.parse(URLstring)); 
      */ 
      mVideoView.setVideoPath(path); 
      mVideoView.setMediaController(new MediaController(this)); 
      mVideoView.requestFocus(); 

     } 
    } 
} 

videoview.xml

<VideoView 
    android:id="@+id/surface_view" 
    android:layout_width="320px" 
    android:layout_height="240px" 
/> 

0

This article提供了類似於代碼你的樣品,雖然有一些差異,尤其是與video.start和你的樣品完全丟失MediaController.show

我建議清理一下你的代碼,並嘗試在上述文章中找到的建議。文章討論中也有一些很好的反饋。

+0

感謝您的回覆。我試過你的鏈接,它顯示不能播放這個視頻,它只適用於mp4link?我想玩.3GP文件 – Ramakrishna 2011-01-27 15:24:16

+0

討論中的人們也建議顯示.3gp文件的代碼。 – 2011-01-27 16:12:31

0

由於@Peter Lillevold建議,你應該首先嚐試一個視頻播放器的參考實現。這裏有一些鏈接:

嘗試這些玩家使用正常的視頻文件中,有一些在this post的鏈接。如果你實現了一個播放器,並且這些參考視頻可以工作,但你的.3gp視頻沒有,那麼問題可能是視頻文件本身沒有按照標準編碼。