- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Android 的流视频播放器中工作,需要显示该流的字幕(如果存在),还需要为用户提供一种选择流中存在的音频 channel 的方法。
我正在从 Android MediaPlayer 切换到 VlcLib 以便能够做到这一点。
但我找不到任何关于如何做到这一点的例子。
有人已经这样做了吗?你能分享一些例子或显示一个线索吗?
非常感谢您的帮助。
我的代码基于互联网上的一个示例,是:
package com.wass08.vlcsimpleplayer;
import com.wass08.vlcsimpleplayer.util.SystemUiHider;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import org.videolan.libvlc.EventHandler;
import org.videolan.libvlc.IVideoPlayer;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaList;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Map;
/**
* An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction.
*
* @see SystemUiHider
*/
public class FullscreenVlcPlayer extends Activity implements SurfaceHolder.Callback, IVideoPlayer
{
private String urlToStream;
// Display Surface
private LinearLayout vlcContainer;
private SurfaceView mSurface;
private SurfaceView mSubtitlesSurface;
private SurfaceHolder holder;
private SurfaceHolder mSubtitlesSurfaceHolder;
// Overlay / Controls
private FrameLayout vlcOverlay;
private ImageView vlcButtonPlayPause;
private Handler handlerOverlay;
private Runnable runnableOverlay;
private Handler handlerSeekbar;
private Runnable runnableSeekbar;
private SeekBar vlcSeekbar;
private TextView vlcDuration;
private TextView overlayTitle;
// media player
private LibVLC libvlc;
private int mVideoWidth;
private int mVideoHeight;
private final static int VideoSizeChanged = -1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Retrieve our url
Bundle b = getIntent().getExtras();
urlToStream = b.getString("url", null);
// HIDE THE ACTION BAR
getActionBar().hide();
// SETUP THE UI
setContentView(R.layout.activity_fullscreen_vlc_player);
// VLC
vlcContainer = (LinearLayout) findViewById(R.id.vlc_container);
mSurface = (SurfaceView) findViewById(R.id.vlc_surface);
mSubtitlesSurface = (SurfaceView) findViewById(R.id.subtitles_surface);
// OVERLAY / CONTROLS
vlcOverlay = (FrameLayout) findViewById(R.id.vlc_overlay);
vlcButtonPlayPause = (ImageView) findViewById(R.id.vlc_button_play_pause);
vlcSeekbar = (SeekBar) findViewById(R.id.vlc_seekbar);
vlcDuration = (TextView) findViewById(R.id.vlc_duration);
overlayTitle = (TextView) findViewById(R.id.vlc_overlay_title);
overlayTitle.setText(urlToStream);
// AUTOSTART
playMovie();
}
private void setSubtitles()
{
/* Only show the subtitles surface when using "Full Acceleration" mode */
//if (libvlc.getHardwareAcceleration() == 2)
//{
mSubtitlesSurface.setVisibility(View.VISIBLE);
//}
Map<Integer, String> mSubtitleTracksList;
Map<Integer, String> mAudioTracksList;
int numSubtitleTracks = libvlc.getSpuTracksCount();
int numAudioTracks = libvlc.getAudioTracksCount();
mSubtitleTracksList = libvlc.getSpuTrackDescription();
mAudioTracksList = libvlc.getAudioTrackDescription();
if (mSubtitleTracksList != null && mSubtitleTracksList.size() > 0)
{
}
if (mAudioTracksList != null && mAudioTracksList.size() > 0)
{
}
Log.d("LIBVLC_PLAYER", "Number of Subtitles Tracks = " + numSubtitleTracks);
Log.d("LIBVLC_PLAYER", "Number of Audio Tracks = " + numAudioTracks);
int i = 0;
for (Map.Entry<Integer, String> entry : mSubtitleTracksList.entrySet())
{
Log.d("LIBVLC_PLAYER", "Subtitle Track " + i + " = " + entry.getValue().toString());
i++;
}
libvlc.setSpuTrack(0);
i = 0;
for (Map.Entry<Integer, String> entry2 : mAudioTracksList.entrySet())
{
Log.d("LIBVLC_PLAYER", "Audio Track " + i + " = " + entry2.getValue().toString());
i++;
}
libvlc.setAudioTrack(0);
}
private final SurfaceHolder.Callback mSubtitlesSurfaceCallback = new SurfaceHolder.Callback()
{
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
if (libvlc != null)
{
libvlc.attachSubtitlesSurface(holder.getSurface());
Log.d("LIBVLC_PLAYER", "SurfaceHolder.Callback: width: " + width + " height: " + height);
}
}
@Override
public void surfaceCreated(SurfaceHolder holder)
{
Log.d("LIBVLC_PLAYER", "SurfaceHolder.Callback -> surfaceCreated");
}
@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
libvlc.detachSubtitlesSurface();
Log.d("LIBVLC_PLAYER", "SurfaceHolder.Callback -> surfaceDestroyed");
}
};
private void showOverlay()
{
vlcOverlay.setVisibility(View.VISIBLE);
}
private void hideOverlay()
{
vlcOverlay.setVisibility(View.GONE);
}
private void setupControls()
{
getActionBar().hide();
// PLAY PAUSE
vlcButtonPlayPause.setOnClickListener(
new View.OnClickListener()
{
@Override
public void onClick(View view)
{
if (libvlc.isPlaying())
{
libvlc.pause();
vlcButtonPlayPause.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_play_over_video));
}
else
{
libvlc.play();
vlcButtonPlayPause.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_pause_over_video));
}
}
}
);
// SEEKBAR
handlerSeekbar = new Handler();
runnableSeekbar = new Runnable()
{
@Override
public void run()
{
if (libvlc != null)
{
long curTime = libvlc.getTime();
long totalTime = (long) (curTime / libvlc.getPosition());
int minutes = (int) (curTime / (60 * 1000));
int seconds = (int) ((curTime / 1000) % 60);
int endMinutes = (int) (totalTime / (60 * 1000));
int endSeconds = (int) ((totalTime / 1000) % 60);
String duration = String.format("%02d:%02d / %02d:%02d", minutes, seconds, endMinutes, endSeconds);
vlcSeekbar.setProgress((int) (libvlc.getPosition() * 100));
vlcDuration.setText(duration);
}
handlerSeekbar.postDelayed(runnableSeekbar, 1000);
}
};
runnableSeekbar.run();
vlcSeekbar.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener()
{
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b)
{
Log.v("NEW POS", "pos is : " + i);
//if (i != 0)
// libvlc.setPosition(((float) i / 100.0f));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
}
}
);
// OVERLAY
handlerOverlay = new Handler();
runnableOverlay = new Runnable()
{
@Override
public void run()
{
vlcOverlay.setVisibility(View.GONE);
toggleFullscreen(true);
}
};
final long timeToDisappear = 3000;
handlerOverlay.postDelayed(runnableOverlay, timeToDisappear);
vlcContainer.setOnClickListener(
new View.OnClickListener()
{
@Override
public void onClick(View view)
{
vlcOverlay.setVisibility(View.VISIBLE);
handlerOverlay.removeCallbacks(runnableOverlay);
handlerOverlay.postDelayed(runnableOverlay, timeToDisappear);
}
}
);
}
public void playMovie()
{
if (libvlc != null && libvlc.isPlaying())
{
return;
}
vlcContainer.setVisibility(View.VISIBLE);
holder = mSurface.getHolder();
holder.addCallback(this);
createPlayer(urlToStream);
}
private void toggleFullscreen(boolean fullscreen)
{
WindowManager.LayoutParams attrs = getWindow().getAttributes();
if (fullscreen)
{
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
vlcContainer.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
else
{
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
}
getWindow().setAttributes(attrs);
}
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
setSize(mVideoWidth, mVideoHeight);
}
@Override
protected void onResume()
{
super.onResume();
}
@Override
protected void onPause()
{
super.onPause();
//releasePlayer();
}
@Override
protected void onDestroy()
{
super.onDestroy();
releasePlayer();
}
/**
* **********
* Surface
* ***********
*/
public void surfaceCreated(SurfaceHolder holder)
{
}
public void surfaceChanged(SurfaceHolder surfaceholder, int format,
int width, int height)
{
if (libvlc != null)
{
libvlc.attachSurface(surfaceholder.getSurface(), this);
}
}
public void surfaceDestroyed(SurfaceHolder surfaceholder)
{
}
private void setSize(int width, int height)
{
mVideoWidth = width;
mVideoHeight = height;
if (mVideoWidth * mVideoHeight <= 1)
{
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
if (holder != null)
{
holder.setFixedSize(mVideoWidth, mVideoHeight);
}
// set display size
ViewGroup.LayoutParams lp = mSurface.getLayoutParams();
lp.width = w;
lp.height = h;
mSurface.setLayoutParams(lp);
mSurface.invalidate();
}
@Override
public void setSurfaceSize(int width, int height, int visible_width,
int visible_height, int sar_num, int sar_den)
{
Message msg = Message.obtain(mHandler, VideoSizeChanged, width, height);
msg.sendToTarget();
}
/**
* **********
* Player
* ***********
*/
private void createPlayer(String media)
{
releasePlayer();
setupControls();
try
{
if (media.length() > 0)
{
Toast toast = Toast.makeText(this, media, Toast.LENGTH_LONG);
toast.setGravity(
Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0,
0
);
toast.show();
}
// Create a new media player
libvlc = LibVLC.getInstance();
libvlc.setHardwareAcceleration(LibVLC.HW_ACCELERATION_FULL);
libvlc.eventVideoPlayerActivityCreated(true);
libvlc.setSubtitlesEncoding("");
libvlc.setAout(LibVLC.AOUT_OPENSLES);
libvlc.setTimeStretching(true);
libvlc.setChroma("RV32");
libvlc.setVerboseMode(true);
LibVLC.restart(this);
EventHandler.getInstance().addHandler(mHandler);
holder.setFormat(PixelFormat.RGBX_8888);
holder.setKeepScreenOn(true);
mSubtitlesSurfaceHolder = mSubtitlesSurface.getHolder();
mSubtitlesSurfaceHolder.setFormat(PixelFormat.RGBA_8888);
mSubtitlesSurface.setZOrderMediaOverlay(true);
//mSubtitlesSurface.setZOrderOnTop(true);
mSubtitlesSurfaceHolder.setFormat(PixelFormat.TRANSLUCENT);
mSubtitlesSurfaceHolder.addCallback(mSubtitlesSurfaceCallback);
MediaList list = libvlc.getMediaList();
list.clear();
list.add(new Media(libvlc, LibVLC.PathToURI(media)), false);
libvlc.setVolume(100);
libvlc.playIndex(0);
}
catch (Exception e)
{
Toast.makeText(this, "Could not create Vlc Player", Toast.LENGTH_LONG).show();
}
}
private void releasePlayer()
{
if (handlerSeekbar != null && runnableSeekbar != null)
{
handlerSeekbar.removeCallbacks(runnableSeekbar);
}
EventHandler.getInstance().removeHandler(mHandler);
if (libvlc == null)
{
return;
}
libvlc.stop();
libvlc.detachSurface();
holder = null;
libvlc.closeAout();
mVideoWidth = 0;
mVideoHeight = 0;
}
/**
* **********
* Events
* ***********
*/
private Handler mHandler = new MyHandler(this);
private static class MyHandler extends Handler
{
private WeakReference<FullscreenVlcPlayer> mOwner;
public MyHandler(FullscreenVlcPlayer owner)
{
mOwner = new WeakReference<FullscreenVlcPlayer>(owner);
}
@Override
public void handleMessage(Message msg)
{
FullscreenVlcPlayer player = mOwner.get();
// Player events
if (msg.what == VideoSizeChanged)
{
player.setSize(msg.arg1, msg.arg2);
return;
}
// Libvlc events
Bundle b = msg.getData();
switch (b.getInt("event"))
{
case EventHandler.MediaPlayerEndReached:
player.releasePlayer();
break;
case EventHandler.MediaPlayerPlaying:
player.setSubtitles();
break;
case EventHandler.MediaPlayerPaused:
case EventHandler.MediaPlayerStopped:
default:
break;
}
}
}
}
最佳答案
这不适用于Android,但我认为可以帮助您
/* Create a new item */
media = libvlc_media_new_path (inst, "BlackBerry.3gp");
/* Create a media player playing environement */
mediaplayer = libvlc_media_player_new_from_media (media);
/* play the media_player */
libvlc_media_player_play (mediaplayer);
//*****************************************************************************
//*****************************************************************************
//********* Subtitle section. Must be after libvlc_media_player_play **********
//*****************************************************************************
//*****************************************************************************
int temp = libvlc_video_set_subtitle_file(mediaplayer, "NewSubFile.srt");
printf("sub status=%d\n", temp);
temp = libvlc_video_set_subtitle_file(mediaplayer, "BlackBerry.srt");
printf("sub status=%d\n", temp);
int sub_count = libvlc_video_get_spu_count(mediaplayer);
printf("sub count=%d\n", sub_count);
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
sleep (10); /* Let it play a bit */
/* No need to keep the media now */
libvlc_media_release (media);
/* Stop playing */
libvlc_media_player_stop (mediaplayer);
/* Free the media_player */
libvlc_media_player_release (mediaplayer);
关于android - 如何使用适用于 Android 的 vlc lib 在视频流中选择音频 channel 和字幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33937386/
我一直在为实时流和静态文件(HTTP 上的 MP3)构建网络广播播放器。我选了Howler.js作为规范化 quirks 的后端的 HTML5 Audio (思考:自动播放、淡入/淡出、进度事件)。
vue移动端input上传视频、音频,供大家参考,具体内容如下 html部分 ?
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 7年前关闭。 Improve this questi
我想在我的程序中访问音频和视频。 MAC里面可以吗? 我们的程序在 Windows 上运行,我使用 directshow 进行音频/视频编程。但我想在 MAC 中开发相同的东西。 有没有像direct
我的应用程序(使用 Flutter 制作,但这应该无关紧要)具有类似于计时器的功能,可以定期(10 秒到 3 分钟)发出滴答声。我在我的 Info.plist 中激活了背景模式 Audio、AirPl
我是 ionic 2 的初学者 我使用了音频文件。 import { Component } from '@angular/core'; import {NavController, Alert
我有一个包含ListView和图片的数据库,我想在每个语音数据中包含它们。我已经尝试过,但是有很多错误。以下是我的java和xml。 数据库.java package com.example.data
我在zend framework 2上建立了一个音乐社交网络。您可以想象它与SoundCloud相同,用户上传歌曲,其他用户播放它们,这些是网站上的基本操作。 我知道将要托管该页面的服务器将需要大量带
我正在尝试在android应用中播放音频,但是在代码中AssetFileDescriptor asset1及其下一行存在错误。这是代码: MediaPlayer mp; @Override prote
我对 WordPress Audio Shortcode有问题。我这样使用它: 但是在前面,在HTML代码中我得到了: document.createElement('audio');
我正在做一项关于降低噪音的滤波技术的实验。我在数据集中的样本是音频文件(.wav),因此,我有:原始录制的音频文件,我将它们与噪声混合,因此变得混合(噪声信号),我将这些噪声信号通过滤波算法传递,输出
一个人会使用哪种类型的神经网络架构将声音映射到其他声音?神经网络擅长学习从序列到其他序列,因此声音增强/生成似乎是它们的一种非常流行的应用(但不幸的是,事实并非如此-我只能找到一个(相当古老的)洋红色
这个让我抓狂: 在专用于此声音播放/录制应用程序的 Vista+ 计算机上,我需要我的应用程序确保(默认)麦克风电平被推到最大。我该怎么做? 我找到了 Core Audio lib ,找到了如何将 I
{ "manifest_version": 2, "name": "Kitten Radio Extension", "description": "Listen while browsi
class Main { WaveFileReader reader; short[] sample; Complex[] tmpComplexArray; publi
我正在使用电话录音软件(android),该软件可以记录2个人在电话中的通话。每个电话的输出是一个音频文件,其中包含来自 call 者和被 call 者的声音。 但是,大多数情况下,运行此软件的电话发
我正在构建一个需要语音激活命令的Web应用程序。我正在使用getUserMedia作为音频输入。 对于语音激活命令,该过程是用户将需要通过记录其语音来“校准”命令。例如,对于“停止”命令,用户将说出“
我正在开发一个Cordova应用程序,并将PouchDB用作数据库,当连接可用时,它将所有信息复制到CouchDB。 我成功存储了简单的文本和图像。 我一直在尝试存储视频和音频,但是没有运气。 我存储
我正在开发web application,我必须在其中使用.MP3的地方使用播放声音,但是会发生问题。 声音为play good in chrome, Firefox,但为safari its not
如何减少音频文件的位深?是否忽略了MSB或LSB?两者混合吗? (旁问:这叫什么?) 最佳答案 TL / DR:将音频曲线高度变量右移至较低位深度 可以将音频视为幅度(Y轴)随时间(X轴)的模拟曲线。
我是一名优秀的程序员,十分优秀!