VLCObject (org.videolan.libvlc.LibVLC) 最终确定但未本地发布 (1 refs):在 android studio 中集成 vlc 时出现此错误

问题描述

**我正在尝试在 android studio 中集成 vlc 播放器,但收到错误消息:无法创建 LibVLC 实例

错误java.lang.AssertionError:VLCObject (org.videolan.libvlc.LibVLC) 最终确定但未本地发布(1 条参考)**

我已代表我尝试了所有方法,但它不断发送此错误

//以下是我试图遵循的互联网代码

public class VideoActivity extends Activity implements IVLCVout.Callback,LibVLC.HardwareaccelerationError {
public final static String TAG = "LibVLCAndroidSample/VideoActivity";

public final static String LOCATION = "com.compdigitec.libvlcandroidsample.VideoActivity.location";

private String mFilePath;

// display surface
private SurfaceView mSurface;
private SurfaceHolder holder;

// media player
private LibVLC libvlc;
private MediaPlayer mMediaPlayer = null;
private int mVideoWidth;
private int mVideoHeight;
private final static int VideoSizeChanged = -1;

/*************
 * Activity
 *************/

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample);

    // Receive path to play from intent
    Intent intent = getIntent();
    mFilePath = intent.getExtras().getString(LOCATION);

    Log.d(TAG,"Playing back " + mFilePath);

    mSurface = (SurfaceView) findViewById(R.id.surface);
    holder = mSurface.getHolder();
    //holder.addCallback(this);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setSize(mVideoWidth,mVideoHeight);
}

@Override
protected void onResume() {
    super.onResume();
    createPlayer(mFilePath);
}

@Override
protected void onPause() {
    super.onPause();
    releasePlayer();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    releasePlayer();
}

/*************
 * Surface
 *************/
private void setSize(int width,int height) {
    mVideoWidth = width;
    mVideoHeight = height;
    if (mVideoWidth * mVideoHeight <= 1)
        return;

    if(holder == null || mSurface == null)
        return;

    // get screen size
    int w = getwindow().getDecorView().getWidth();
    int h = getwindow().getDecorView().getHeight();

    // getwindow().getDecorView() doesn't always take orientation into
    // account,we have to correct the values
    boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    if (w > h && isPortrait || w < h && !isPortrait) {
        int i = w;
        w = h;
        h = i;
    }

    float videoAR = (float) mVideoWidth / (float) mVideoHeight;
    float screenAR = (float) w / (float) h;

    if (screenAR < videoAR)
        h = (int) (w / videoAR);
    else
        w = (int) (h * videoAR);

    // force surface buffer size
    holder.setFixedSize(mVideoWidth,mVideoHeight);

    // set display size
    LayoutParams lp = mSurface.getLayoutParams();
    lp.width = w;
    lp.height = h;
    mSurface.setLayoutParams(lp);
    mSurface.invalidate();
}

/*************
 * Player
 *************/

private void createPlayer(String media) {
    releasePlayer();
    try {
        if (media.length() > 0) {
            Toast toast = Toast.makeText(this,media,Toast.LENGTH_LONG);
            toast.setGravity(Gravity.BottOM | Gravity.CENTER_HORIZONTAL,0);
            toast.show();
        }

        // Create LibVLC
        // Todo: make this more robust,and sync with audio demo
        ArrayList<String> options = new ArrayList<String>();
        //options.add("--subsdec-encoding <encoding>");
        options.add("--aout=opensles");
        options.add("--audio-time-stretch"); // time stretching
        options.add("-vvv"); // verbosity
        libvlc = new LibVLC(options);
        libvlc.setonHardwareaccelerationError(this);
        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.setSubtitlesView(mSurfaceSubtitles);
        vout.addCallback(this);
        vout.attachViews();

        Media m = new Media(libvlc,media);
        mMediaPlayer.setMedia(m);
        mMediaPlayer.play();
    } catch (Exception e) {
        Toast.makeText(this,"Error creating player!",Toast.LENGTH_LONG).show();
    }
}

// Todo: handle this cleaner
private void releasePlayer() {
    if (libvlc == null)
        return;
    mMediaPlayer.stop();
    final IVLCVout vout = mMediaPlayer.getVLCVout();
    vout.removeCallback(this);
    vout.detachViews();
    holder = null;
    libvlc.release();
    libvlc = null;

    mVideoWidth = 0;
    mVideoHeight = 0;
}

/*************
 * Events
 *************/

private MediaPlayer.EventListener mPlayerListener = new MyPlayerListener(this);

@Override
public void onNewLayout(IVLCVout vout,int width,int height,int visibleWidth,int visibleHeight,int sarNum,int sarDen) {
    if (width * height == 0)
        return;

    // store video size
    mVideoWidth = width;
    mVideoHeight = height;
    setSize(mVideoWidth,mVideoHeight);
}

@Override
public void onSurfacesCreated(IVLCVout vout) {

}

@Override
public void onSurfacesDestroyed(IVLCVout vout) {

}

private static class MyPlayerListener implements MediaPlayer.EventListener {
    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;
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...