如何解决在surfaceView上调整视频大小
我目前正在使用RTSP流媒体应用程序,但SurfaceView出现了问题,该流的播放效果很好,但是由于某种原因,视频被放到了屏幕的左下角。 下面的图片
下面是显示流设置的代码。
public class VideoActivity extends Activity implements IVLCVout.Callback
{
public final static String TAG = "VideoActivity";
public static final String RTSP_URL = "rtsp";
// display surface
private SurfaceView mSurface;
private SurfaceHolder holder;
// media player
private LibVLC libvlc;
private MediaPlayer mMediaPlayer = null;
private MediaPlayer.EventListener mPlayerListener = new MyPlayerListener(this);
private String rtspUrl;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.sample);
// get URL
Intent intent = getIntent();
rtspUrl = intent.getExtras().getString(RTSP_URL);
Log.d(TAG,"Playing Back " + rtspUrl);
mSurface = (SurfaceView) findViewById(R.id.surface);
holder = mSurface.getHolder();
ArrayList<String> options = new ArrayList<String>();
options.add("--aout=opensles");
options.add("--audio-time-stretch"); // time stretching
options.add("-vvv"); // verbosity
options.add("--aout=opensles");
options.add("--avcodec-codec=h264");
options.add("--file-logging");
options.add("--logfile=vlc-log.txt");
libvlc = new LibVLC(getApplicationContext(),options);
holder.setKeepScreenOn(true);
// Create media player
mMediaPlayer = new MediaPlayer(libvlc);
mMediaPlayer.setEventListener(mPlayerListener);
// Set up video output
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.setVideoView(mSurface);
vout.addCallback(this);
vout.attachViews();
Media m = new Media(libvlc,Uri.parse(rtspUrl));
mMediaPlayer.setMedia(m);
mMediaPlayer.play();
}
@Override
protected void onResume()
{
super.onResume();
// createPlayer(mFilePath);
}
@Override
protected void onPause()
{
super.onPause();
releasePlayer();
}
@Override
protected void onDestroy()
{
super.onDestroy();
releasePlayer();
}
@Override
public void onSurfacesCreated(IVLCVout vlcVout) { }
@Override
public void onSurfacesDestroyed(IVLCVout vlcVout) { }
@Override
public void onPointerCaptureChanged(boolean hasCapture) { }
public void releasePlayer()
{
if (libvlc == null)
{
return;
}
mMediaPlayer.stop();
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.removeCallback(this);
vout.detachViews();
holder = null;
libvlc.release();
libvlc = null;
}
}
class MyPlayerListener extends Activity implements MediaPlayer.EventListener
{
private Button button;
private static String TAG = "PlayerListener";
private WeakReference<VideoActivity> mOwner;
public MyPlayerListener(VideoActivity owner)
{
mOwner = new WeakReference<VideoActivity>(owner);
}
@Override
public void onEvent(MediaPlayer.Event event)
{
VideoActivity player = mOwner.get();
switch(event.type)
{
case MediaPlayer.Event.EndReached:
Log.d(TAG,"MediaPlayerEndReached");
player.releasePlayer();
break;
case MediaPlayer.Event.Playing:
case MediaPlayer.Event.Paused:
case MediaPlayer.Event.Stopped:
default:
break;
}
}
}
下面是带有SurfaceView的XML,在以前的项目中,使用Surface View时,我使用了与下面相同的布局,在屏幕上获得了完整图像。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:id="@+id/surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
</RelativeLayout>
如果可能的话,有人可以指出正确的方向来解决这个问题。
谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。