如何让 VideoView 使用 Drive link 播放视频?

How do I make the VideoView play the video with the Drive link?

所以我正在尝试让 VideoView 播放来自云端硬盘的 link 的视频。我进行了网络安全配置,但仍然无法播放视频(“您的视频无法播放。”)我意识到问题不在于代码,而在于link。我尝试了 links 来自已经制作好的播放器,有些没有。我只想让视频工作。使用驱动器 link 或其他方法。我要告诉你我做了什么。如果有人能帮助我,我将不胜感激。

代码:

 VideoView videoView = findViewById(R.id.SY);
    Uri uri = Uri.parse("https://drive.google.com/file/d/1CRJ8tL-DyjD0Nwd7ezkboGm6570zMf4C/view?usp=sharing");
    videoView.setVideoURI(uri);

    MediaController mc = new MyMediaController(videoView.getContext());
    mc.setMediaPlayer(videoView);
    videoView.setMediaController(mc);

    videoView.start();

    videoView.setOnCompletionListener(mp -> onBackPressed());

网络xml:

<network-security-config>
<domain-config>
    <domain includeSubdomains="true">diligent_app.com</domain>
    <trust-anchors>
        <certificates src="system"/>
    </trust-anchors>
</domain-config>
Manifest:
        android:usesCleartextTraffic="true"
        android:networkSecurityConfig="@xml/network"

我得到的错误

2021-08-30 14:53:35.338 4582-7140/? E/WindowManager: win=Window{4c93299 
u0 com.example.diligent/com.diligent_app.diligent.yoga.Yoga} 
destroySurfaces: appStopped=true win.mWindowRemovalAllowed=false 
win.mRemoveOnExit=false win.mViewVisibility=8 
caller=com.android.server.wm.ActivityRecord.destroySurfaces:5227 
com.android.server.wm.ActivityRecord.destroySurfaces:5208 
com.android.server.wm.ActivityRecord.notifyAppStopped:5267 
com.android.server.wm.ActivityRecord.activityStopped:5894 
com.android.server.wm.ActivityTaskManagerService.activityStopped:2584 
android.app.IActivityTaskManager$Stub.onTransact:2215 
android.os.Binder.execTransactInternal:1190 
2021-08-30 14:53:35.605 4302-16264/? E/GenericSource: text/html from 
getMIMEType()
2021-08-30 14:53:35.605 12855-15380/com.example.diligent 
E/MediaPlayerNative: error (1, -1015)
2021-08-30 14:53:35.606 12855-12855/com.example.diligent E/MediaPlayer: 
Error (1,-1015)
2021-08-30 14:53:37.695 4582-6879/? E/TaskPersister: File error 
accessing recents directory (directory doesn't exist?).
2021-08-30 14:53:42.774 4582-4618/? E/BatteryStatsService: Unable to load 
Power Hal or power.stats HAL

提前致谢。

在 URL 中带有 sharing 的 link 只会将您带到网页(不是视频数据)。

要将视频数据下载到您的播放器中,请尝试:

Uri uri = Uri.parse("https://drive.google.com/uc?export=download&id=1CRJ8tL-DyjD0Nwd7ezkboGm6570zMf4C");