2011-01-27 78 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视频没有,那么问题可能是视频文件本身没有按照标准编码。