嗨,我是 Android 开发的新手。我想在我的 android 应用程序中为媒体播放器添加字幕。我已经搜索并找到了一个方法,即 addTimedTextSource(...) 但它给出了错误 java.lang.NoSuchMethodError: android.media.MediaPlayer.addTimedTextSource
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.video_view);
mp = new MediaPlayer();
// vw = (VideoView)findViewById(R.id.video_intent);
Intent intent = getIntent();
path = intent.getStringExtra("path");
Log.d("File path ::::::::::::::::::",path);
try {
mp.setDataSource("file://"+path);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
String mimeType = getMimeType("file://mnt/sdcard/BarbieGirl.srt");
// mp.selectTrack(index);
try {
mp.addTimedTextSource(path, mimeType);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
}
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
}
谁能告诉我如何使用它或任何关于如何在 android 中显示字幕轨道的想法。
谢谢