gpt4 book ai didi

android - 我想从互联网路径的视频 View 中获取视频大小(以 MB 为单位)

转载 作者:太空狗 更新时间:2023-10-29 14:06:33 25 4
gpt4 key购买 nike

我正在尝试获取视频文件大小并在开始播放视频之前将其显示在布局中。

我尝试了很多方法,但都不行

video_player_view = (VideoView) findViewById(R.id.videoView2);
media_Controller = new MediaController(this);
dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
int height = dm.heightPixels;
int width = dm.widthPixels;
try {
video_player_view.setMinimumWidth(width);
video_player_view.setMinimumHeight(height);
} catch (Exception e) {}
video_player_view.setMediaController(media_Controller);
video_player_view.setVideoPath(path);
video_player_view.start();


if (savedInstanceState != null) {
video_player_view.seekTo(savedInstanceState.getInt("current_position"));
}

vidTitle = (TextView) findViewById(R.id.vidTitle);
vidDesc = (TextView) findViewById(R.id.vidDesc);
vidSize = (TextView) findViewById(R.id.vidSize);
vidDur = (TextView) findViewById(R.id.vidDur);
vidDownload = (ImageButton) findViewById(R.id.vidDownload);
vidFav = (CheckBox) findViewById(R.id.vidFav);
vidTitle.setText(singleVideoInfo.title);
vidDesc.setText(singleVideoInfo.description);
video_player_view.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
progressBarCircularIndeterminate.setVisibility(View.GONE);
int duration = video_player_view.getDuration() / 1000;
int hours = duration / 3600;
int minutes = (duration / 60) - (hours * 60);
int seconds = duration - (hours * 3600) - (minutes * 60);
String formatted = String.format("Duration: %d:%02d:%02d", hours, minutes, seconds);
vidDur.setText(formatted);
//vidSize.setText("???");


}
});

我希望在 onPreparedlistener 中初始化视频时显示视频大小

我试过了

URL myUrl = new URL("http://your_url.com/file.mp4");
URLConnection urlConnection = myUrl.openConnection();
urlConnection.connect();
int file_size = urlConnection.getContentLength();
file_size = file_size /1024;

还有这个

URL myUrl = new URL("http://your_url.com/file.mp4");
myConnection = myUrl.openConnection();
List headersize = myConnection.getHeaderFields().get("content-Lenght");

什么都行不通请帮忙

最佳答案

我认为您的操作方式存在大小限制。试试这个方法:

final URL uri=new URL("http://your_url.com/file.mp4");
URLConnection connection;
try
{
connection=uri.openConnection();
connection.connect();
final String contentLengthStr=ucon.getHeaderField("content-length");
// do whatever
}

catch(final IOException exception)
{
}

编辑:我刚刚注意到你尝试过类似的东西,但你拼错了长度,也许就是这样

关于android - 我想从互联网路径的视频 View 中获取视频大小(以 MB 为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31982855/

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