【问题标题】:Playing a YouTube video in a android application using LibVLC使用 LibVLC 在 android 应用程序中播放 YouTube 视频
【发布时间】:2021-03-16 12:25:12
【问题描述】:

我只是想制作一个简单的 android 应用程序,它将播放我作为链接提供的 YouTube 视频。这是代码

package com.example.videoplayer;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;

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

import java.util.ArrayList;
import java.util.logging.StreamHandler;

public class MainActivity extends AppCompatActivity {

private static String TAG = "MainActivity";
private VideoView vv;
private Button bt;

private Context mContext = this;

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    vv = findViewById(R.id.videoView);
    bt = findViewById(R.id.button);

}

public void setUpMediaStream(View view) {
    final ArrayList<String> args = new ArrayList<>();
    args.add("-vvv");
    mLibVLC = new LibVLC(mContext, args);
    Log.d(TAG, "setUpMediaStream() creating media player");
    mMediaPlayer = new MediaPlayer(mLibVLC);
    Log.d(TAG, "setUpMediaStream() setting video view");
    String yt = "https://www.youtube.com/watch?v=tXHoqsnRD-U";
    Media media = new Media(mLibVLC, Uri.parse(yt));

    mMediaPlayer.setMedia(media);
    media.release();

    mMediaPlayer.setAspectRatio(null);
    mMediaPlayer.setScale(0);
    Log.d(TAG, "setUpMediaStream() playing media");
    mMediaPlayer.play();
}}

问题是我按下播放按钮时遇到以下异常 java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.videoplayer-JGI3RJow0fmaB6c-w2WuVQ==/base.apk"],nativeLibraryDirectories=[/data/ app/com.example.videoplayer-JGI3RJow0fmaB6c-w2WuVQ==/lib/arm64, /system/lib64]]] 找不到“libc++_shared.so”

任何回应都是有帮助的。

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
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"
tools:context=".MainActivity">

<VideoView
    android:id="@+id/videoView"
    android:layout_width="370dp"
    android:layout_height="390dp"
    android:layout_marginTop="104dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.487"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="72dp"
    android:onClick="setUpMediaStream"
    android:text="@string/play"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"`enter code here`
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/videoView"
    app:layout_constraintVertical_bias="0.153" /> </androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

    标签: android android-studio libvlc unsatisfiedlinkerror


    【解决方案1】:

    我无法复制您的异常,但是...

    我认为你不能只传入一个网页的 url,vlc 不是 WebView - 它需要是一个可播放的文件,例如 https://jell.yfish.us/media/jellyfish-3-mbps-hd-h264.mkv - 并且一定要在清单:

    <uses-permission android:name="android.permission.INTERNET" />
    

    我还认为您需要将布局中的VideoView 替换为org.videolan.libvlc.util.VLCVideoLayout,并在实例化MediaPlayer 后将其传递给mediaPlayer.attachViews()

    我可以通过这些步骤播放视频。

    ** 编辑 **

    LibVLC 也有一个示例项目,在他们的应用级 build.gradle 文件中他们指定 jni 目录:

    android {
    ...
        sourceSets {
            main {
                jni.srcDirs = [] // Prevent gradle from building native code with ndk; we have our own Makefile for it.
                jniLibs.srcDir 'jni/libs' // Where generated .so files are placed
                assets.srcDirs = ['src/main/assets', '../assets/']
            }
        }
    }
    

    https://code.videolan.org/videolan/libvlc-android-samples/-/tree/master/java_sample

    【讨论】:

    • 嗨@jana 我明白了你所说的,但我没有达到你所说的那样。能否请您分享您的更改......
    • 我完全使用了您的代码,除了我提到的更改..它一定是特定设备上的问题...您是否设置了应用程序级 build.gradle 文件的源集在他们的示例项目中? code.videolan.org/videolan/libvlc-android-samples/-/blob/master/…
    • 非常感谢您的帮助。学到了很多。最后一个帮助视频播放非常滞后,我在 log-cat 中找到了这些日志。你能帮我整理一下吗
    • E/VLC:[000000706f843490/75b6] http 流:本地流 1 错误:取消 (0x8) E/VLC:[000000706f843490/75b5] http 流:本地流 1 错误:流关闭(0x5 ) 2020-12-07 12:41:58.714 30093-30370/com.example.videoplayer E/VLC: [000000706f9cef10/76a2] libvlc 解码器: 输出: 2141391878 未知, 1920x1088 步幅 1920 1088, 裁剪 0 0 0 0E/ [000000704f545d10/7698] libvlc 窗口:请求 1 未实现 E/VLC:[0000007052c5f890/7698] libvlc vout 显示:无法获取字幕表面 E/VLC:[000000704f545d10/7698] libvlc 窗口:请求 1 未实现
    • 你试过播放没有字幕的视频吗?
    猜你喜欢
    • 2020-02-28
    • 2012-07-05
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 2017-01-11
    • 2012-07-18
    • 2012-10-17
    相关资源
    最近更新 更多