您好我正在尝试从网址获取视频数据。我的项目写得很快。他们在那里使用dataWithContentsOfURL
。有人知道什么是android
data = [NSData dataWithContentsOfURL:videoUrl options:0 error:&error];
答案 0 :(得分:1)
您的问题非常通用,但如果您想播放来自公共网址的视频,则可以执行以下操作(摘自Android文档:https://developer.android.com/guide/topics/media/mediaplayer.html):
String url = "http://........"; // your URL here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare(); // might take long! (for buffering, etc)
mediaPlayer.start();
如果您需要更高级的内容,则应尝试使用ExoPlayer:https://developer.android.com/guide/topics/media/exoplayer.html
但是如果你只是想下载视频数据以某种方式进行操作,你可以使用普通的HttpURLConnection(不在主线程上):
URL url = new URL("http://.....");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
OutputStream output = null; // whatever is your destination (file, memory, network)
InputStream input = conn.getInputStream();
byte data[] = new byte[4096];
int count;
while ((count = input.read(data)) != -1) {
output.write(data, 0, count);
}
input.close();
output.close();
conn.disconnect();