0

嗨,我想在 android 手机中播放 .3GP 视频文件。我尝试了下面的代码,但它显示无法播放视频。所以请告诉我我会怎么做

这是我的代码

 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>
4

3 回答 3

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();

        }
    }
}

视频视图.xml

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

于 2011-01-27T15:25:25.960 回答
0

正如@Peter Lillevold 建议的那样,您应该首先尝试视频播放器的参考实现。以下是一些链接:

用已知的工作视频文件尝试这些播放器,这篇文章中有一些链接。如果您实现了播放器,并且这些参考视频可以正常工作,但您的 .3gp 视频不能正常工作,那么问题可能是视频文件本身没有按照标准编码。

于 2011-01-27T15:36:11.513 回答
0

本文提供的代码与您的示例类似,但存在一些差异,尤其是在video.start您的示例完全缺失的情况下MediaController.show

我建议稍微清理一下您的代码,然后尝试上述文章中的建议。在文章讨论中也有一些很好的反馈。

于 2011-01-27T15:18:23.913 回答