应该有字幕控制器已经设置 Mediaplayer 错误 Android
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20087804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Should have subtitle controller already set Mediaplayer error Android
提问by Sai
Whenever I play a media, it shows a warning in DDMS Should have subtitle controller already set
每当我播放媒体时,它都会在 DDMS 中显示警告 Should have subtitle controller already set
MY CODE:
我的代码:
private void start() {
mediaPlayer.start();
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.release();
}
});
}
DDMS LOG
日志
Should have subtitle controller already set
info/warning (2, 0)
应该已经设置了字幕控制器
信息/警告 (2, 0)
When I searched on Google, not even a single topic related to it. How can I get rid of or disable this?
当我在 Google 上搜索时,甚至没有一个主题与之相关。我怎样才能摆脱或禁用它?
回答by Hacketo
A developer recently added subtitle support to VideoView.
一位开发人员最近为 VideoView 添加了字幕支持。
When the MediaPlayer
starts playing a music (or other source), it checks if there is a SubtitleController and shows this message if it's not set.
It doesn't seem to care about if the source you want to play is a music or video. Not sure why he did that.
当MediaPlayer
开始播放音乐(或其他来源)时,它会检查是否有 SubtitleController 并在未设置时显示此消息。它似乎并不关心您要播放的源是音乐还是视频。不知道他为什么这样做。
Short answer:Don't care about this "Exception".
简短回答:不要在意这个“例外”。
Edit :
编辑 :
Still present in Lollipop,
仍然存在于棒棒糖中,
If MediaPlayer
is only used to play audio files and you really want to remove these errors in the logcat, the code bellow set an empty SubtitleController
to the MediaPlayer
.
如果MediaPlayer
仅用于播放音频文件并且您确实想在 logcat 中删除这些错误,则下面的代码empty SubtitleController
将MediaPlayer
.
It should not be used in production environment and may have some side effects.
它不应该在生产环境中使用,并且可能会产生一些副作用。
static MediaPlayer getMediaPlayer(Context context){
MediaPlayer mediaplayer = new MediaPlayer();
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
return mediaplayer;
}
try {
Class<?> cMediaTimeProvider = Class.forName( "android.media.MediaTimeProvider" );
Class<?> cSubtitleController = Class.forName( "android.media.SubtitleController" );
Class<?> iSubtitleControllerAnchor = Class.forName( "android.media.SubtitleController$Anchor" );
Class<?> iSubtitleControllerListener = Class.forName( "android.media.SubtitleController$Listener" );
Constructor constructor = cSubtitleController.getConstructor(new Class[]{Context.class, cMediaTimeProvider, iSubtitleControllerListener});
Object subtitleInstance = constructor.newInstance(context, null, null);
Field f = cSubtitleController.getDeclaredField("mHandler");
f.setAccessible(true);
try {
f.set(subtitleInstance, new Handler());
}
catch (IllegalAccessException e) {return mediaplayer;}
finally {
f.setAccessible(false);
}
Method setsubtitleanchor = mediaplayer.getClass().getMethod("setSubtitleAnchor", cSubtitleController, iSubtitleControllerAnchor);
setsubtitleanchor.invoke(mediaplayer, subtitleInstance, null);
//Log.e("", "subtitle is setted :p");
} catch (Exception e) {}
return mediaplayer;
}
This code is trying to do the following from the hidden API
此代码试图从隐藏的 API 执行以下操作
SubtitleController sc = new SubtitleController(context, null, null);
sc.mHandler = new Handler();
mediaplayer.setSubtitleAnchor(sc, null)
回答by StefanoM5
To remove message on logcat, i add a subtitle to track. On windows, right click on track -> Property -> Details -> insert a text on subtitle. Done :)
为了删除 logcat 上的消息,我添加了一个字幕来跟踪。在 Windows 上,右键单击轨道 -> 属性 -> 详细信息 -> 在字幕上插入文本。完毕 :)
回答by Faizan Khan
Also you can only set mediaPlayer.reset()
and in onDestroy
set it to release.
您也只能设置mediaPlayer.reset()
并onDestroy
设置它以释放。