在surfaceView上调整视频大小

问题描述

我目前正在使用RTSP流媒体应用程序,但SurfaceView出现了问题,该流的播放效果很好,但是由于某种原因,视频被放到了屏幕的左下角。 下面的图片

enter image description here

下面是显示流设置的代码

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 (将#修改为@)