我在rtsp上有一段视频,我想让视频视图适合我的所有视图宽度。这是一个问题:视频的分辨率非常低且平方,所以视频视图会拉伸我的视频。这是我的代码:
<VideoView
android:id="@+id/videoView"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_below="@+id/idHeader"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:layout_gravity="center"
android:layout_centerInParent="true"/>
在片段内
//find the video view and assign the media controller and the button.
videoView = (VideoView) view.findViewById(R.id.videoView);
mediaC = new MediaController(getContext());
playButton = (ImageView) view.findViewById(R.id.playButton);
playButton.setImageResource(R.drawable.ic_play_arrow_24dp);
playButton.setClickable(false);
//declare progress bar for the video buffering.
mProgressBar = (ProgressBar) view.findViewById(R.id.videoProgressBar);
mProgressBar.setVisibility(View.INVISIBLE);
//set the background and video controller for the video.
videoView.setBackgroundColor(Color.BLACK);
videoView.setMediaController(mediaC);
mediaC.setAnchorView(videoView);
mediaC.setVisibility(View.INVISIBLE);
//declare the MediaPlayer listener for the video buffering and starts the handler for stop video
//after 15 seconds.
final MediaPlayer.OnInfoListener onInfoToPlayStateListener = new MediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
switch (what) {
case MediaPlayer.MEDIA_INFO_BUFFERING_END: {
mProgressBar.setVisibility(View.INVISIBLE);
videoView.setBackgroundColor(Color.TRANSPARENT);
int delay = 15000; //milliseconds
Handler handler = new Handler();
handler.postDelayed(new Runnable(){
public void run(){
videoView.stopPlayback();
videoView.clearAnimation();
videoView.suspend(); // clears media player
videoView.setVideoURI(null);
videoView.setVisibility(View.VISIBLE);
videoView.setBackgroundColor(Color.BLACK);
videoView = null;
playButton.setImageResource(R.drawable.ic_play_arrow_24dp);
playButton.setVisibility(View.VISIBLE);
}
}, delay);
return true;
}
}
return false;
}
};
videoView.setOnInfoListener(onInfoToPlayStateListener);
//declare the playButton click listener for play and stop video.
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(videoView == null){
videoView = (VideoView) view.findViewById(R.id.videoView);
videoView.setMediaController(mediaC);
mediaC.setAnchorView(videoView);
mediaC.setVisibility(View.INVISIBLE);
}
if(videoView.isPlaying()){
playButton.setImageResource(R.drawable.ic_play_arrow_24dp);
playButton.setVisibility(View.VISIBLE);
videoView.stopPlayback();
videoView = null;
}
else{
mProgressBar.setVisibility(View.VISIBLE);
playButton.setImageResource(R.drawable.ic_pause_black_24dp);
playButton.setVisibility(View.INVISIBLE);
videoView.setVideoURI(source, headers);
videoView.start();
}
}
});
我想添加相同的黑带以保持视频比例。 Thare是一种我可以添加的方法,而不是视频视图吗?
谢谢