当我尝试在Android应用程序中播放视频时,收到消息“无法播放此视频”。我使用VideoView的活动:
package midamcorp.com.burgerkingapp;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.VideoView;
import java.net.URI;
public class videoViewer extends AppCompatActivity {
VideoView vidView;
ImageButton back;
final String path = "www.midamcorp.com";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_viewer);
vidView = (VideoView) findViewById(R.id.videoView);
back = (ImageButton) findViewById(R.id.backButton);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
Intent i = getIntent();
String vidPath = i.getStringExtra("path");
try {
Uri.Builder builder = new Uri.Builder();
builder.scheme("http");
builder.authority(path);
builder.appendPath("videos");
builder.appendPath(vidPath);
Uri uri = builder.build();
Log.i("Uri is ", uri.toString());
vidView.setVideoURI(uri);
vidView.start();
} catch (Exception e) {
Log.e(this.getClass().toString(), "error with URI");
}
}
}
部分输出
05-11 08:30:05.022 21669-21669/midamcorp.com.burgerkingapp I/Uri is: http://www.midamcorp.com/videos/whopperDog.wmv
05-11 08:30:05.163 21669-21669/midamcorp.com.burgerkingapp W/MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: No content provider: http://www.midamcorp.com/videos/whopperDog.wmv
每当我在浏览器中导航到视频路径时,它会下载而不是播放,但我认为这可能与浏览器设置有关。这可能与这个问题有关吗?我真的很感激任何帮助。
答案 0 :(得分:0)
你没有设置MediaController只是试试..
MediaController mediacontroller = new MediaController(
mContext);
mediacontroller.setAnchorView(vidView );
// Get the URL from String VideoURL
Uri video = Uri.parse(vidPath);
vidView .setMediaController(mediacontroller);
vidView .setVideoURI(video);
答案 1 :(得分:0)
你试过avi或mp4文件吗? 我不认为Android在视频视图中支持wmv文件。
请参阅此回答Android Media Player Library
http://developer.android.com/guide/appendix/media-formats.html