whi*_*rue 5 video android vlc libvlc vlc-android
经过 3 天的旅程,我终于编译了 libvlc-3.0.0-2.1.0.aar,用于将 VLC 播放器嵌入到我的 Android(电视)应用程序中。
\n\n改编LibVLC Android 示例后到我的项目中后,我终于运行了该应用程序。
\n\n问题:仅播放音频。视频永远不会出现(表面视图保持黑色)。我用不同的视频进行了测试,图像从未出现。
\n\n知道为什么视频没有播放吗?这是我尝试播放的视频示例(http://www.sample-videos.com/video/mp4/240/big_buck_bunny_240p_50mb.mp4)
\n\n我的设置:\n我已经刻录了Android 电视图像刻录到我的 RPI3 中,并且该应用程序正在其中运行。
\n\n更新:我已经尝试过 VLC 原始应用程序(来自 apk),并且发生了同样的情况。
\n\n这是我的活动的代码:
\n\npublic class MyVideoPlayerActivity extends Activity implements IVLCVout.Callback{\n\n public final static String TAG = "VideoActivity";\n\n // display surface\n private SurfaceView mSurface;\n private SurfaceHolder holder;\n\n // media player\n private LibVLC libvlc;\n private MediaPlayer mMediaPlayer = null;\n private int mVideoWidth;\n private int mVideoHeight;\n private final static int VideoSizeChanged = -1;\n\n private String mFilePath;\n\n @Override\n protected void onCreate(Bundle pSavedInstanceState) {\n super.onCreate(pSavedInstanceState);\n\n setContentView(R.layout.activity_my_video_player);\n\n mSurface = (SurfaceView) findViewById(R.id.surface);\n holder = mSurface.getHolder();\n //mFilePath = new String("http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8");\n //http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4\n //http://www.sample-videos.com/video/mp4/240/big_buck_bunny_240p_50mb.mp4\n mFilePath = new String("http://www.sample-videos.com/video/3gp/240/big_buck_bunny_240p_30mb.3gp");\n\n }\n\n @Override\n public void onConfigurationChanged(Configuration newConfig) {\n super.onConfigurationChanged(newConfig);\n setSize(mVideoWidth, mVideoHeight);\n }\n\n @Override\n protected void onResume() {\n super.onResume();\n createPlayer(mFilePath);\n }\n\n @Override\n protected void onPause() {\n super.onPause();\n releasePlayer();\n }\n\n @Override\n protected void onDestroy() {\n super.onDestroy();\n releasePlayer();\n }\n\n /*************\n * Surface\n *************/\n private void setSize(int width, int height) {\n mVideoWidth = width;\n mVideoHeight = height;\n if (mVideoWidth * mVideoHeight <= 1)\n return;\n\n if(holder == null || mSurface == null)\n return;\n\n // get screen size\n int w = getWindow().getDecorView().getWidth();\n int h = getWindow().getDecorView().getHeight();\n\n // getWindow().getDecorView() doesn\'t always take orientation into\n // account, we have to correct the values\n boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;\n if (w > h && isPortrait || w < h && !isPortrait) {\n int i = w;\n w = h;\n h = i;\n }\n\n float videoAR = (float) mVideoWidth / (float) mVideoHeight;\n float screenAR = (float) w / (float) h;\n\n if (screenAR < videoAR)\n h = (int) (w / videoAR);\n else\n w = (int) (h * videoAR);\n\n // force surface buffer size\n holder.setFixedSize(mVideoWidth, mVideoHeight);\n\n // set display size\n LayoutParams lp = mSurface.getLayoutParams();\n lp.width = w;\n lp.height = h;\n mSurface.setLayoutParams(lp);\n mSurface.invalidate();\n }\n\n /*************\n * Player\n *************/\n\n private void createPlayer(String media) {\n releasePlayer();\n try {\n if (media.length() > 0) {\n Toast toast = Toast.makeText(this, media, Toast.LENGTH_LONG);\n toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0,\n 0);\n toast.show();\n }\n\n // Create LibVLC\n // TODO: make this more robust, and sync with audio demo\n ArrayList<String> options = new ArrayList<String>();\n //options.add("--subsdec-encoding <encoding>");\n options.add("--aout=opensles");\n options.add("--audio-time-stretch"); // time stretching\n //options.add("-vvv"); // verbosity\n libvlc = new LibVLC(this, options);\n holder.setKeepScreenOn(true);\n\n // Create media player\n mMediaPlayer = new MediaPlayer(libvlc);\n mMediaPlayer.setEventListener(mPlayerListener);\n\n // Set up video output\n final IVLCVout vout = mMediaPlayer.getVLCVout();\n vout.setVideoView(mSurface);\n //vout.setSubtitlesView(mSurfaceSubtitles);\n vout.addCallback(this);\n vout.attachViews();\n\n Media m = new Media(libvlc, (Uri.parse(media)) );\n mMediaPlayer.setMedia(m);\n mMediaPlayer.play();\n } catch (Exception e) {\n Toast.makeText(this, "Error creating player!", Toast.LENGTH_LONG).show();\n }\n }\n\n // TODO: handle this cleaner\n private void releasePlayer() {\n if (libvlc == null)\n return;\n\n Log.d(TAG, "Releasing Player");\n mMediaPlayer.stop();\n final IVLCVout vout = mMediaPlayer.getVLCVout();\n vout.removeCallback(this);\n vout.detachViews();\n holder = null;\n libvlc.release();\n libvlc = null;\n\n mVideoWidth = 0;\n mVideoHeight = 0;\n }\n\n public void finishActivity() {\n finish();\n }\n /*************\n * Events\n *************/\n\n private MediaPlayer.EventListener mPlayerListener = new MyPlayerListener(this);\n\n @Override\n public void onNewLayout(IVLCVout vout, int width, int height, int visibleWidth, int visibleHeight, int sarNum, int sarDen) {\n if (width * height == 0)\n return;\n\n // store video size\n mVideoWidth = width;\n mVideoHeight = height;\n setSize(mVideoWidth, mVideoHeight);\n Log.d(TAG, "OnNewLayout " + mVideoWidth + "x" + mVideoHeight);\n }\n\n @Override\n public void onSurfacesCreated(IVLCVout vout) {\n Log.d(TAG, "onSurfacesCreated " + vout);\n }\n\n @Override\n public void onSurfacesDestroyed(IVLCVout vout) {\n Log.d(TAG, "onSurfacesDestroyed " + vout);\n }\n\n\n private static class MyPlayerListener implements MediaPlayer.EventListener {\n private WeakReference<MyVideoPlayerActivity> mOwner;\n\n public MyPlayerListener(MyVideoPlayerActivity owner) {\n mOwner = new WeakReference<MyVideoPlayerActivity>(owner);\n }\n\n @Override\n public void onEvent(org.videolan.libvlc.MediaPlayer.Event event) {\n MyVideoPlayerActivity player = mOwner.get();\n\n switch(event.type) {\n case org.videolan.libvlc.MediaPlayer.Event.EndReached:\n Log.d(TAG, "MediaPlayerEndReached");\n player.releasePlayer();\n break;\n case org.videolan.libvlc.MediaPlayer.Event.Playing:\n Log.d(TAG, "MediaPlayer Playing");\n case org.videolan.libvlc.MediaPlayer.Event.Paused:\n Log.d(TAG, "MediaPlayer Paused");\n case org.videolan.libvlc.MediaPlayer.Event.Stopped:\n Log.d(TAG, "MediaPlayer Stopped");\n //player.releasePlayer();\n //player.finishActivity();\n default:\n break;\n }\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n\n这是资源/布局的代码:
\n\n<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\n xmlns:tools="http://schemas.android.com/tools"\n android:layout_width="match_parent"\n android:layout_height="match_parent"\n android:baselineAligned="false"\n android:orientation="horizontal"\n tools:context=".MyVideoPlayerActivity" >\n\n\n <FrameLayout\n android:layout_width="500dp"\n android:layout_height="300dp" >\n\n <SurfaceView\n android:id="@+id/surface"\n android:layout_width="fill_parent"\n android:layout_height="fill_parent"\n android:layout_gravity="center" />\n </FrameLayout>\n\n</LinearLayout>\nRun Code Online (Sandbox Code Playgroud)\n\n这是 adb 日志的副本:\n此链接中的完整日志
\n\nW/OpenGLRenderer: Bitmap too large to be uploaded into a texture (2556x1438, max=2048x2048)\nW/OpenGLRenderer: Bitmap too large to be uploaded into a texture (2556x1438, max=2048x2048)\nD/VLC: [a2fb0db8/656c706d] core libvlc: VLC media player - 3.0.0-git Vetinari\nD/VLC: [a2fb0db8/79746976] core libvlc: Copyright \xc2\xa9 1996-2016 the VideoLAN team\nD/VLC: [a2fb0db8/160013] core libvlc: revision 2.2.0-git-8758-gb0f06e8\nD/VLC: [a2fb0db8/a0497a18] core libvlc: configured with ../configure \'--host=arm-linux-androideabi\' \'--build=x86_64-unknown-linux\' \'--with-contrib=/home/edup/sources/vlc-android/vlc/contrib/arm-linux-androideabi\' \'--enable-neon\' \'--disable-nls\' \'--enable-live555\' \'--enable-realrtsp\' \'--enable-avformat\' \'--enable-swscale\' \'--enable-avcodec\' \'--enable-opus\' \'--enable-opensles\' \'--enable-mkv\' \'--enable-taglib\' \'--enable-dvbpsi\' \'--disable-vlc\' \'--disable-shared\' \'--disable-update-check\' \'--disable-vlm\' \'--disable-dbus\' \'--enable-lua\' \'--disable-vcd\' \'--disable-v4l2\' \'--disable-gnomevfs\' \'--enable-dvdread\' \'--enable-dvdnav\' \'--disable-bluray\' \'--disable-linsys\' \'--disable-decklink\' \'--disable-libva\' \'--disable-dv1394\' \'--enable-mod\' \'--disable-sid\' \'--disable-gme\' \'--disable-tremor\' \'--disable-mad\' \'--enable-mpg123\' \'--disable-dca\' \'--disable-sdl-image\' \'--enable-zvbi\' \'--disable-fluidsynth\' \'--enable-fluidlite\' \'--disable-jack\' \'--disable-pulse\' \'--disable-alsa\' \'--disable-samplerate\' \'--disable-sdl\' \'--disable-xcb\' \nD/VLC: [a2fb0db8/a2f78580] core libvlc: plug-ins loaded: 286 modules\nD/VLC: [a2f3a2c8/a2f78580] core logger: looking for logger module matching "any": 4 candidates\nD/VLC: [a2f3a2c8/120000] core logger: using logger module "android_logger"\nD/VLC: [a2fb0db8/af3] core libvlc: translation test: code is "C"\nD/VLC: [a2f3a328/af3] core keystore: looking for keystore module matching "memory": 3 candidates\nD/VLC: [a2f3a328/af3] core keystore: using keystore module "memory"\nD/VLC: [a2fb0db8/af3] core libvlc: CPU has capabilities ARM_NEON FPU \nD/VLC: [a2fb1bb8/af3] core generic: creating audio output\nD/VLC: [9e542528/af3] core audio output: looking for audio output module matching "opensles": 4 candidates\nW/libOpenSLES: class OutputMix interface 0 requested but unavailable MPH=43\nD/VLC: [9e542528/af3] core audio output: using audio output module "opensles_android"\nD/VLC: [a2fb1bb8/af3] core generic: keeping audio output\nW/EGL-DRI2: Native format mismatch: 0x1 != 0x5\nD/VideoActivity: onSurfacesCreated org.videolan.libvlc.AWindow@95d92e7\nD/VLC: [a2f9f718/af3] core input: Creating an input for \'big_buck_bunny.mp4\'\nW/OpenGLRenderer: Bitmap too large to be uploaded into a texture (2556x1438, max=2048x2048)\nD/VLC: [a2f9f718/b5f] core input: using timeshift granularity of 50 MiB\nD/VLC: [a2f9f718/b5f] core input: using default timeshift path\nD/VLC: [a2f9f718/b5f] core input: `http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4\' gives access `http\' demux `\' path `clips.vorwaerts-gmbh.de/big_buck_bunny.mp4\'\nD/VLC: [af3f38e8/b5f] core input source: specified demux: any\nD/VLC: [af3f38e8/b5f] core input source: creating demux: access=\'http\' demux=\'any\' location=\'clips.vorwaerts-gmbh.de/big_buck_bunny.mp4\' file=\'(null)\'\nD/VLC: [a2f24ea8/b5f] core demux: looking for access_demux module matching "http": 6 candidates\nD/VLC: [a2f24ea8/b5f] core demux: no access_demux modules matched\nD/VLC: [af3f3a28/b5f] core stream: creating access: http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4\n\n************[I\'ve cut this part for characters restriction reason. Please follow the link above for full log]**************\n\nD/VLC: [a2f24ea8/b5f] mp4 demux: Found video Rtp: m=video\nW/VLC: [a2f24ea8/b5f] mp4 demux: elst box found\nD/VLC: [a2f24ea8/b5f] mp4 demux: - [0] duration=60095ms media time=0ms) rate=1.0\nD/VLC: [a2f24ea8/b5f] mp4 demux: track[Id 0x3] read 240 chunk\nW/OpenGLRenderer: Bitmap too large to be uploaded into a texture (2556x1438, max=2048x2048)\nW/OpenGLRenderer: Bitmap too large to be uploaded into a texture (2556x1438, max=2048x2048)\nW/OpenGLRenderer: Bitmap too large to be uploaded into a texture (2556x1438, max=2048x2048)\nW/VLC: [a2f24ea8/b5f] mp4 demux: STTS table of 2 entries\nD/VLC: [a2f24ea8/b5f] mp4 demux: track[Id 0x3] read 1440 samples length:60s\nD/VLC: [a2f24ea8/b5f] essetup demux: Unrecognized FourCC rtp \nD/VLC: [a2f24ea8/b5f] mp4 demux: adding track[Id 0x3] video (disable) language eng\nD/VLC: [a2f24ea8/b5f] mp4 demux: Found audio Rtp: m=audio\nW/VLC: [a2f24ea8/b5f] mp4 demux: elst box found\nD/VLC: [a2f24ea8/b5f] mp4 demux: - [0] duration=60095ms media time=0ms) rate=1.0\nD/VLC: [a2f24ea8/b5f] mp4 demux: track[Id 0x4] read 241 chunk\nW/VLC: [a2f24ea8/b5f] mp4 demux: STTS table of 3 entries\nD/VLC: [a2f24ea8/b5f] mp4 demux: track[Id 0x4] read 648 samples length:60s\nD/VLC: [a2f24ea8/b5f] mp4 demux: adding track[Id 0x4] audio (disable) language eng\nD/VLC: [a2f24ea8/b5f] fragments demux: fragment offset 24, data 37130<->5510872 @0, durations (null)\nD/VLC: [a2f24ea8/b5f] core demux: using demux module "mp4"\nD/VLC: [af3f3a28/b62] h1conn stream: outgoing request:\n GET /big_buck_bunny.mp4 HTTP/1.1\n Host: clips.vorwaerts-gmbh.de\n Accept: */*\n Accept-Language: en_US\n User-Agent: VLC/3.0.0-git LibVLC/3.0.0-git\n If-Match: "5416d8-47f21fa7d3300"\n Range: bytes=5510872-\nD/VLC: [a2fa42a8/b5f] core decoder: looking for decoder module matching "mediacodec_ndk,iomx,all": 40 candidates\nD/VLC: [a2fa42a8/b5f] avcodec decoder: CPU flags: 0x0000003f\nD/VLC: [a2fa42a8/b5f] avcodec decoder: codec (aac) started\nD/VLC: [a2fa42a8/b5f] core decoder: using decoder module "avcodec"\nD/VLC: [a2fa49a8/b5f] core decoder: looking for decoder module matching "mediacodec_ndk,iomx,all": 40 candidates\nD/VLC: [a2fa49a8/b5f] avcodec decoder: CPU flags: 0x0000003f\nD/VLC: [af3f3a28/b62] h1conn stream: incoming response:\n HTTP/1.1 416 Requested Range Not Satisfiable\n Date: Sat, 03 Sep 2016 20:40:58 GMT\n Content-Type: text/html\n Transfer-Encoding: chunked\n Connection: keep-alive\n Set-Cookie: __cfduid=d491331e46f4fe1fd02450fd87b2704231472935258; expires=Sun, 03-Sep-17 20:40:58 GMT; path=/; domain=.vorwaerts-gmbh.de; HttpOnly\n Cache-Control: public, max-age=31536000\n Expires: Sun, 03 Sep 2017 20:40:58 GMT\n CF-Cache-Status: HIT\n Content-Range: bytes */5510872\n Server: cloudflare-nginx\n CF-RAY: 2dcc0517a62d06d0-LHR\nD/VLC: [af3f3b68/b62] prefetch stream: end of stream\nD/VLC: [a2fa49a8/b5f] avcodec decoder: allowing 4 thread(s) for decoding\nI/Choreographer: Skipped 38 frames! The application may be doing too much work on its main thread.\nD/VLC: [a2fa49a8/b5f] avcodec decoder: codec (h264) started\nD/VLC: [a2fa49a8/b5f] avcodec decoder: using frame thread mode with 4 threads\nD/VLC: [a2fa49a8/b5f] core decoder: using decoder module "avcodec"\nD/VLC: [9cf662f8/b5f] core demux meta: looking for meta reader module matching "any": 2 candidates\nD/VLC: [9cf662f8/b5f] lua demux meta: Trying Lua scripts in /data/user/0/com.biti_kids.biti/app_vlc/.share/lua/meta/reader\nD/VLC: [9cf662f8/b5f] lua demux meta: Trying Lua scripts in /data/app/com.biti_kids.biti-1/lib/arm/vlc/lua/meta/reader\nD/VLC: [9cf662f8/b5f] lua demux meta: Trying Lua scripts in /data/app/com.biti_kids.biti-1/share/vlc/lua/meta/reader\nD/VLC: [9cf662f8/b5f] core demux meta: no meta reader modules matched\nD/VLC: [a2f9f718/b5f] core input: `http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4\' successfully opened\nD/VLC: [a2f24ea8/b5f] mp4 demux: elst (0) gives 0ms (movie)-> 0ms (track)\nD/VLC: [a2f24ea8/b5f] mp4 demux: elst (0) gives 0ms (movie)-> 0ms (track)\nD/VLC: [a2f24ea8/b5f] mp4 demux: track[Id 0x2] using Sync Sample Box (stss)\nD/VLC: [a2f24ea8/b5f] mp4 demux: stss gives 0 --> 0 (sample number)\nW/OpenGLRenderer: Bitmap too large to be uploaded into a texture (2556x1438, max=2048x2048)\nW/OpenGLRenderer: Bitmap too large to be uploaded into a texture (2556x1438, max=2048x2048)\nW/OpenGLRenderer: Bitmap too large to be uploaded into a texture (2556x1438, max=2048x2048)\nD/VLC: [af3f3a28/b6b] transport stream: connecting to clips.vorwaerts-gmbh.de port 80 ...\nD/VLC: [af3f3a28/b62] h1conn stream: outgoing request:\n GET /big_buck_bunny.mp4 HTTP/1.1\n Host: clips.vorwaerts-gmbh.de\n User-Agent: VLC/3.0.0-git LibVLC/3.0.0-git\n Range: bytes=37130-\nD/VLC: [af3f3a28/b62] h1conn stream: incoming response:\n HTTP/1.1 206 Partial Content\n Date: Sat, 03 Sep 2016 20:40:59 GMT\n Content-Type: video/mp4\n Content-Length: 5473742\n Connection: keep-alive\n CF-Cache-Status: HIT\n Content-Range: bytes 37130-5510871/5510872\n Server: cloudflare-nginx\n CF-RAY: 2dcc051a2b100cd7-LHR\nD/VLC: [af3f3a28/b62] h1conn stream: connection failed\nD/VLC: [a2f9f718/b5f] core input: Buffering 0%\nD/VLC: [a2fb1bb8/b65] core generic: reusing audio output\nE/VLC-std: aout_get_native_sample_rate: 48000\nW/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 1, track 22050 Hz, output 48000 Hz\nD/VLC: [9e542528/b65] core audio output: output \'s16l\' 22050 Hz Stereo frame=1 samples/4 bytes\nD/VLC: [a2fb6ed8/b65] core volume: looking for audio volume module matching "any": 3 candidates\nD/VLC: [a2fb6ed8/b65] core volume: using audio volume module "integer_mixer"\nD/VLC: [9e542528/b65] core audio output: input \'f32l\' 22050 Hz Stereo frame=1 samples/8 bytes\nD/VLC: [a2fa5ea8/b65] core audio filter: looking for audio filter module matching "scaletempo": 13 candidates\nD/VLC: [a2fa5ea8/b65] scaletempo audio filter: format: 22050 rate, 2 nch, 4 bps, fl32\nD/VLC: [a2fa5ea8/b65] scaletempo audio filter: params: 30 stride, 0.200 overlap, 14 search\nD/VLC: [a2fa5ea8/b65] scaletempo audio filter: 1.000 scale, 661.000 stride_in, 661 stride_out, 529 standing, 132 overlap, 308 search, 1101 queue, fl32 mode\nD/VLC: [a2fa5ea8/b65] core audio filter: using audio filter module "scaletempo"\nD/VLC: [9e542528/b65] core audio output: conversion: \'f32l\'->\'f32l\' 22050 Hz->22050 Hz Stereo->Stereo\nD/VLC: [9e542528/b65] core audio output: conversion pipeline complete\nD/VLC: [9e542528/b65] core audio output: conversion: \'f32l\'->\'s16l\' 22050 Hz->22050 Hz Stereo->Stereo\nD/VLC: [a2fa6228/b65] core audio converter: looking for audio converter module matching "any": 7 candidates\nD/VLC: [a2fa6228/b65] audio_format audio converter: f32l->s16l, bits per sample: 32->16\nD/VLC: [a2fa6228/b65] core audio converter: using audio converter module "audio_format"\nD/VLC: [9e542528/b65] core audio output: conversion pipeline complete\nD/VLC: [a2fa65a8/b65] core audio resampler: looking for audio resampler module matching "any": 2 candidates\nD/VLC: [a2fa65a8/b65] core audio resampler: using audio resampler module "ugly"\nD/VLC: [a2
可悲的事实是libvlc 示例已经相当过时了。
正如发帖者所评论的,也许避免 VLC 是一种选择。
不管好坏,libvlc 在我的旧 Android Tab(nexus 7)上工作。
至于网上的示例,使用旧版本 NDK 编译的 libvlc 似乎包含 TEXTREL,并且 github 上的许多示例都受其影响。
我使用自编译的 libvlc-3.0.0-2.1.1.aar 并进行了以下调整。
删除的接口:
LibVLC.HardwareAccelerationError //is now gone(idk what replaces this!).
Run Code Online (Sandbox Code Playgroud)
更改了实施:
IVLCVout.callback.onNewLayout
Run Code Online (Sandbox Code Playgroud)
到
IVLCVout.OnNewVideoLayoutListener.onNewVideoLayout
Run Code Online (Sandbox Code Playgroud)
实例化 LibVLC
mLibVLC = new LibVLC();
mLibVLC = new LibVLC(options);
Run Code Online (Sandbox Code Playgroud)
到
mLibVLC = new LibVLC(getApplicationContext());
mLibVLC = new LibVLC(getApplicationContext(),options);
Run Code Online (Sandbox Code Playgroud)
它应该向我们显示可以播放的视频列表,但我只能看到一个仅播放音频的按钮,因此如果您想测试 VLC 视频功能,也许您需要添加一些代码来启动 VideoActivity 并调用它。
public void startVideoIntent(String path){
Intent intent = new Intent(MainActivity.this, VideoActivity.class);
intent.putExtra(VideoActivity.LOCATION, (String) path);
mPlayingVideo = true;
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)