我正在使用VideoView
来播放来自网址的视频。当我运行app时,它会在logcat
Can't play this video
以及msg以下
Couldn't open file on client side; trying server side:java.io.FileNotFoundException: No content provider:aklearningsolutions.com/video/Nursery%20Rhymes.mp4
Unable to open content: aklearningsolutions.com/video/Nursery%20Rhymes.mp4
java.io.IOException: setDataSource failed.
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1095)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1069)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1023)
下面是我的活动文件
package com.dp.videostore.Activity;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.TextureView;
import android.widget.MediaController;
import android.widget.VideoView;
import com.dp.videostore.R;
public class PlayerActivity extends AppCompatActivity {
VideoView videoView;
String url = "aklearningsolutions.com/video/Nursery Rhymes.mp4";
MediaController mc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
videoView = (VideoView)findViewById(R.id.video_view);
try {
mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
videoView.setMediaController(mc);
Uri link = Uri.parse(url.replace(" ","%20"));
videoView.setVideoURI(link);
videoView.requestFocus();
videoView.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
以下是我的xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.dp.videostore.Activity.PlayerActivity">
<VideoView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/video_view"/>
</RelativeLayout>
当我在网络浏览器中点击视频链接时,视频在浏览器中播放得非常好
答案 0 :(得分:4)
尝试将协议放入您的网址。事实上,Android认为您正在使用ContentProvider
String url = "http://aklearningsolutions.com/video/Nursery Rhymes.mp4";