android电视框架中libvlc android和tvplayer的问题

xj3cbfub  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(763)

我正在尝试设计一个小模块来接收rtp流量,并将其显示在android电视的直播频道应用程序中。有问题的应用程序接收声音和一切,但当涉及到在屏幕上绘制图像,这发生在我的记录。
日志:

08-23 02:03:06.339 31050 31195 E VLC     : [e6831cb0/79db] libvlc window: request 1 not implemented
08-23 02:03:06.339 31050 31195 D VLC     : [d573bc30/79db] libvlc vout display: VoutDisplayEvent 'resize' 1920x1080
08-23 02:03:06.339 31050 31195 D VLC     : [e6831db0/79db] libvlc gl: looking for opengl es2 module matching "any": 1 candidates
08-23 02:03:06.341 31050 31195 D VLC     : [e6831db0/79db] libvlc gl: no opengl es2 modules matched
08-23 02:03:06.341 31050 31195 E VLC     : [e6831cb0/79db] libvlc window: request 1 not implemented
08-23 02:03:06.341 31050 31195 D VLC     : [d573bc30/79db] libvlc vout display: VoutDisplayEvent 'resize' 1920x1080
08-23 02:03:06.341 31050 31195 D VLC     : [d573bc30/79db] libvlc vout display: no vout display modules matched
08-23 02:03:06.341 31050 31098 E VLC     : [ed07a330/797a] libvlc video output: video output creation failed
08-23 02:03:06.343 31050 31098 D VLC     : [d5751cb0/797a] libvlc spu text: removing module "freetype"
08-23 02:03:06.345 31050 31098 D VLC     : [d5753830/797a] libvlc scale: removing module "yuvp"
08-23 02:03:06.345 31050 31098 D VLC     : [d5752bb0/797a] libvlc scale: removing module "swscale"
08-23 02:03:06.346 31050 31098 E VLC     : [e684a730/797a] libvlc decoder: failed to create video output

appplayer.java文件:

/*
 * Copyright 2016 The Android Open Source Project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.neirth.player;

import android.content.Context;
import android.content.res.Resources;
import android.media.PlaybackParams;
import android.net.Uri;
import android.util.DisplayMetrics;
import android.view.Surface;
import android.view.SurfaceView;

import com.google.android.media.tv.companionlibrary.TvPlayer;

import org.videolan.libvlc.IVLCVout;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaPlayer;

import java.util.ArrayList;

/**
 * A wrapper around ExoPlayer which implements TvPlayer. This is the class that actually renders
 * the video, subtitles and all these sorts of things.
 */
public class AppPlayer implements TvPlayer {
    private LibVLC libVlc;
    private MediaPlayer player;

    /**
     * AppPlayer constructor
     * @param context Context
     */
    public AppPlayer(Context context) {
        ArrayList<String> options = new ArrayList<>();
        options.add("-vv");
        options.add("--aout=opensles");

        libVlc = new LibVLC(context, options);
        player = new MediaPlayer(libVlc);
    }

    /**
     * Load media
     * @param mediaUri Media URI
     */
    public void loadMedia(String mediaUri) {
        loadMedia(Uri.parse(mediaUri));
    }

    /**
     * Load media
     * @param mediaUri Media URI
     */
    public void loadMedia(Uri mediaUri) {
        final Media media = new Media(libVlc, mediaUri);
        media.setHWDecoderEnabled(true, false);
        media.addOption(":clock-jitter=0");
        media.addOption(":clock-synchro=0");
        media.addOption(":network-caching=1000"); // In milliseconds
        media.addOption(":sout-keep");
        media.addOption(":audio-time-stretch");

        player.setMedia(media);

        media.release();
    }

    /**
     * Release player
     */
    public void release() {
        player.release();
        libVlc.release();
    }

    /**
     * Set surface
     * @param surface Video surface
     */
    @Override
    public void setSurface(Surface surface) {
        final IVLCVout vlcVout = player.getVLCVout();
        if (surface != null) {
            DisplayMetrics dm = Resources.getSystem().getDisplayMetrics();
            vlcVout.setVideoSurface(surface,null);
            vlcVout.setWindowSize(dm.widthPixels, dm.heightPixels);
            vlcVout.attachViews();
        } else {
            vlcVout.detachViews();
        }
    }

    /**
     * Get current position
     * @return Current position in milliseconds
     */
    @Override
    public long getCurrentPosition() {
        return (long) (player.getPosition() * 1000);
    }

    /**
     * Get duration
     * @return Duration in milliseconds
     */
    @Override
    public long getDuration() {
        return player.getLength();
    }

    /**
     * Start or resume player
     */
    @Override
    public void play() {
        player.play();
    }

    /**
     * Pause player
     */
    @Override
    public void pause() {
        player.pause();
    }

    /**
     * Stop player
     */
    public void stop() {
        player.stop();
    }

    /**
     * Seek to
     * @param position Position in milliseconds
     */
    @Override
    public void seekTo(long position) {
        float pos = (float) position;
        pos /= 1000;
        player.setPosition(pos);
    }

    /**
     * Set volume
     * @param volume Volume between 0 and 1
     */
    @Override
    public void setVolume(float volume) {
        player.setVolume((int) (volume * 100));
    }

    @Override
    public void setPlaybackParams(PlaybackParams params) {}

    @Override
    public void registerCallback(Callback callback) {}

    @Override
    public void unregisterCallback(Callback callback) {}
}

如果能回答这个问题,我将不胜感激。

rqcrx0a6

rqcrx0a61#

问题来自你的 setSurface() 方法。
这是一个独立的工作示例

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaPlayer;
import org.videolan.libvlc.util.VLCVideoLayout;

import java.io.IOException;
import java.util.ArrayList;

public class JavaActivity extends AppCompatActivity  {
    private static final boolean USE_TEXTURE_VIEW = false;
    private static final boolean ENABLE_SUBTITLES = true;
    private static final String ASSET_FILENAME = "bbb.m4v";

    private VLCVideoLayout mVideoLayout = null;

    private LibVLC mLibVLC = null;
    private MediaPlayer mMediaPlayer = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        final ArrayList<String> args = new ArrayList<>();
        args.add("-vvv");
        mLibVLC = new LibVLC(this, args);
        mMediaPlayer = new MediaPlayer(mLibVLC);

        mVideoLayout = findViewById(R.id.video_layout);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMediaPlayer.release();
        mLibVLC.release();
    }

    @Override
    protected void onStart() {
        super.onStart();

        mMediaPlayer.attachViews(mVideoLayout, null, ENABLE_SUBTITLES, USE_TEXTURE_VIEW);

        try {
            final Media media = new Media(mLibVLC, getAssets().openFd(ASSET_FILENAME));
            mMediaPlayer.setMedia(media);
            media.release();
        } catch (IOException e) {
            throw new RuntimeException("Invalid asset folder");
        }
        mMediaPlayer.play();
    }

    @Override
    protected void onStop() {
        super.onStop();

        mMediaPlayer.stop();
        mMediaPlayer.detachViews();
    }
}

相关问题