gpt4 book ai didi

java - 无法在videoview android中播放来自url的视频

转载 作者:行者123 更新时间:2023-12-01 18:46:41 24 4
gpt4 key购买 nike

我正在尝试在视频 View 中播放我自己的本地服务器上的视频。我给它我的服务器的 URL。

http://admin:admin@192.168.0.3:8732/cam4/ERecordings/4_UNIVIEW_192.168.1.13/01-07-2020/14-39-23.mp4

我可以在任何浏览器中访问此链接并播放视频,但我的应用程序无法播放它。

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final VideoView videoView = findViewById(R.id.videoplayer);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Buffering please wait!!");
progressDialog.show();
// Uri uri = Uri.parse("https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4");
Uri uri = Uri.parse("http://admin:admin@192.168.0.3:8732/cam4/ERecordings/4_UNIVIEW_192.168.1.13/01-07-2020/14-39-23.mp4");
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
//videoView.setVideoPath("http://playready.directtaps.net/smoothstreaming/ISMAAACHE/Taxi3_AACHE.mp4");
videoView.requestFocus();
videoView.start();
try{
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
}
});
}
catch (Exception e){
Toast.makeText(this,"can not play ", Toast.LENGTH_SHORT).show();
}

}

}

权限:为了测试,我已授予该应用程序所有权限。

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

错误:

W/MediaPlayer: Couldn't open http://admin:admin@192.168.0.3:8732/cam4/ERecordings/4_UNIVIEW_192.168.1.13/01-07-2020/14-39-23.mp4: java.io.FileNotFoundException: No content provider: http://admin:admin@192.168.0.3:8732/cam4/ERecordings/4_UNIVIEW_192.168.1.13/01-07-2020/14-39-23.mp4

我可以从任何浏览器访问它,甚至在移动设备上也是如此。即使 Vlc 和 Mx 播放器 Android 应用程序也可以播放它。如果我输入任何私有(private)服务器地址,那么它就可以正常播放。我在同一个 wifi 网络上。

更新:我在 Android list 中添加了权限 android:usesCleartextTraffic="true"但现在出现错误

E/MediaPlayerNative: error (1, -2147483648)
E/MediaPlayer: Error (1,-2147483648)
D/VideoView: Error: 1,-2147483648

更新 2:- 我将视频文件放入 IIS 服务器中,这次工作正常。但在我的主程序中我使用的是 apache 服务器。早些时候,我使用 Libvlc android 集成,它能够播放视频,但 videoview android 无法播放相同的 url。下面的网址工作正常。

String url = "http://192.168.0.4/a1.ts";

最佳答案

试试这个,它会对你有用,

try {
val link = "https://www.radiantmediaplayer.com/media/bbb-360p.mp4"
val videoView = findViewById(R.id.videoview) as VideoView
val mediaController = MediaController(this)
mediaController.setAnchorView(videoView)
val progressDialog = ProgressDialog(this)
progressDialog.setMessage("Loading video please wait!!!")
progressDialog.show()
val video = Uri.parse(link)
videoView.setMediaController(mediaController)
videoView.setVideoURI(video)
videoView.requestFocus();
videoView.start()
try {
videoView.setOnPreparedListener(object : MediaPlayer.OnPreparedListener {
override fun onPrepared(mp: MediaPlayer) {
progressDialog.dismiss()
}
})
} catch (e: Exception) {
Toast.makeText(this, "can not play ", Toast.LENGTH_SHORT).show()
}


} catch (e: Exception) {
Toast.makeText(this, "Error loading video", Toast.LENGTH_SHORT).show()
}

AndroidManifest.xml.文件中的权限

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

关于java - 无法在videoview android中播放来自url的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59820889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com