java.io.FileNotFoundException:没有内容提供者:
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47005151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.io.FileNotFoundException: No content provider:
提问by Bella
i have problem to reproduce a video with videoView.setVideoPath();
我在重现视频时遇到问题 videoView.setVideoPath();
in fact video doesn't reproduce..i don't know why. Video's path is correct.
事实上,视频不能重现……我不知道为什么。视频路径正确。
This is my code:
这是我的代码:
public class MainActivity extends AppCompatActivity {
private VideoView videoView;
private int position = 0;
private MediaController mediaController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.videoView);
// Set the media controller buttons
if (mediaController == null) {
mediaController = new MediaController(MainActivity.this);
// Set the videoView that acts as the anchor for the MediaController.
mediaController.setAnchorView(videoView);
// Set MediaController for VideoView
videoView.setMediaController(mediaController);
}
try {
// ID of video file.
String videoUrl="https://www.youtube.com/watch?v=JHdmkP-nfsA";
videoView.setVideoPath(videoUrl);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoView.requestFocus();
// When the video file ready for playback.
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mediaPlayer) {
videoView.seekTo(position);
if (position == 0) {
videoView.start();
}
// When video Screen change size.
mediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
// Re-Set the videoView that acts as the anchor for the MediaController
mediaController.setAnchorView(videoView);
}
});
}
});
}
}
Who can help me?
谁能帮我?
Thanks in advance everybody!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
提前谢谢大家!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
LOGCAT:
逻辑猫:
Couldn't open https://www.youtube.com/watch?v=JHdmkP-nfsA: java.io.FileNotFoundException: No content provider: https://www.youtube.com/watch?v=JHdmkP-nfsA
10-29 12:27:28.419 25932-25932/com.example.marco.ud D/MediaPlayer: setDataSource IOException | SecurityException happend :
java.io.FileNotFoundException: No content provider: https://www.youtube.com/watch?v=JHdmkP-nfsA
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1137)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:988)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:911)
at android.media.MediaPlayer.attemptDataSource(MediaPlayer.java:1102)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1093)
at android.widget.VideoView.openVideo(VideoView.java:356)
at android.widget.VideoView.-wrap0(VideoView.java)
at android.widget.VideoView.surfaceCreated(VideoView.java:632)
at android.view.SurfaceView.updateWindow(SurfaceView.java:656)
at android.view.SurfaceView.onPreDraw(SurfaceView.java:172)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1013)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2510)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1519)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7113)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at android.view.Choreographer.doFrame(Choreographer.java:638)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6780)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
回答by D_Alpha
You can not play a YouTubevideo directly to the VideoViewor ExoPlayer, for that, first you have to download the video then set the locale path of that video to the method VideoView.setVideoPath("path")
您不能直接将YouTube视频播放到VideoView或ExoPlayer,为此,首先您必须下载视频,然后将该视频的区域设置路径设置为方法VideoView.setVideoPath("path")
If you want to play only YouTubevideos then use YouTube Android Player API, and if you only want to play other remote videos (.mp4, .ogg, .3gp etc.) then use the method VideoView.setVideoURI("uri")
.
如果您只想播放YouTube视频,请使用YouTube Android Player API,如果您只想播放其他远程视频(.mp4、.ogg、.3gp 等),请使用 方法VideoView.setVideoURI("uri")
。
Example-
例子-
String videoUrl = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
try {
// Start the MediaController
MediaController mediacontroller = new MediaController(this);
mediacontroller.setAnchorView(videoview);
// Get the URL from String videoUrl
Uri video = Uri.parse(videoUrl);
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoview.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
videoview.start();
}
});
回答by damian
VideoView.setVideoPath
requires a local path on the device. You should try setVideoURI
instead if you want to play a remote MP4 or something else. VideoView Documentation
VideoView.setVideoPath
需要设备上的本地路径。setVideoURI
如果您想播放远程 MP4 或其他内容,您应该尝试。VideoView 文档
If you want to embed YouTube videos in your app, consider using the YouTube Android Player APIor using something like a WebView
如果您想在您的应用中嵌入 YouTube 视频,请考虑使用YouTube Android Player API或使用类似WebView
回答by Hitesh Sahu
I had same issue but it was because of corporate proxy server. I used same app over my mobile internet and it started working. Hope it save someone's time
我有同样的问题,但这是因为公司代理服务器。我在我的移动互联网上使用了相同的应用程序,它开始工作了。希望它可以节省某人的时间
回答by huynq0911
I recommend using ExoPlayerinstead of VideoView:
我建议使用ExoPlayer而不是VideoView:
app gradle:
应用程序等级:
implementation 'com.google.android.exoplayer:exoplayer:2.10.8'
layout xml:
布局xml:
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
java code:
代码:
PlayerView videoView = findViewById(R.id.video_view);
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this);
videoView.setPlayer(player);
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "yourApplicationName"));
// This is the MediaSource representing the media to be played.
MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(fileEntity.getPath()));
// Prepare the player with the source.
player.prepare(videoSource);
player.setPlayWhenReady(true);
回答by Nilesh Deokar
You are using VideoView
which
您正在使用VideoView
哪个
Displays a video file. The VideoView class can load images from various sources (such as resources or content providers).
显示视频文件。VideoView 类可以从各种来源(例如资源或内容提供者)加载图像。
You might want to try setVideoURI
你可能想试试 setVideoURI
Or : ExoPlayerif min SDK > 16
或者:ExoPlayer如果最小 SDK > 16
Or use SurfaceView
:
或使用SurfaceView
:
SurfaceView surfaceView = (SurfaceView)findViewById(R.id.surfaceView);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
mediaPlayer.setDataSource(STREAM_URL);
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.start();
}
Ref : https://developer.android.com/reference/android/widget/VideoView.html
参考:https: //developer.android.com/reference/android/widget/VideoView.html