【问题标题】:How to play an mp4 video from server in android?如何在 android 中从服务器播放 mp4 视频?
【发布时间】:2012-06-12 06:29:38
【问题描述】:

我能够显示来自服务器的 3gp 视频。但是当我尝试播放 mp4 视频时,它会显示一条警告,说对不起,无法播放此视频。请在这方面帮助我。

package com.play.video;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class PlayvideofromserverActivity extends Activity
{
    private VideoView vView;
    private String vSource;


    @Override
    public void onCreate(Bundle savedInstanceState) 
    { 

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);


        vView = (VideoView)findViewById(R.id.vview);


        vView.requestFocus();


            vSource ="http://server.com/testvideo.mp4";
            vView.setVideoURI(Uri.parse(vSource));


        vView.setMediaController(new MediaController(this));


        vView.start();
    }
} 

【问题讨论】:

  • 取决于您的服务器设置。您的服务器是否允许 mp4 MIMEType?
  • 是否使用模拟器进行测试?如果是,请在设备上尝试

标签: android video mp4


【解决方案1】:

试试这个代码。对你有帮助。

myVideoView.setMediaController(new MediaController(this));
myVideoView.setVideoPath(videoSource);
myVideoView.requestFocus();
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
  public void onPrepared(MediaPlayer mp) {
    myVideoView.start();
  }
});

谢谢

【讨论】:

    【解决方案2】:

    Android 并不总是播放 mp4。

    MP4 只是一个容器——它里面的视频和音频流都会被编码成不同的格式。

    Android natively only supports certain types of formats.这里有一个列表:

    http://developer.android.com/guide/appendix/media-formats.html

    确保video and audio encoding type is supported。仅仅因为它说“mp4”并不意味着它应该可以播放。

    归功于Ken Wolf

    【讨论】:

      【解决方案3】:

      试试这个代码

      MediaController mc = new MediaController(this);
      videoView.setMediaController(mc);
      
      String s=Common.videofilepath;
      //Set the path of Video or URI
      videoView.setVideoURI(Uri.parse(Common.videofilepath));
      
      //Set the focus
      videoView.requestFocus();
      videoView.start();
      

      【讨论】:

      • 您好,感谢您的回复...但是上面的代码有什么共同点?
      • Common.videofilepath = "httP//server.com/testvideo.mp4"
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-28
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多