Android studio 此处地图中的语音说明不起作用
我想通过Android上的HERE Maps实现语音指令,我使用了示例代码“LiveSightGuidanceActivity”,并从中添加了与语音指令相关的代码 但是声音不起作用!我发现了错误 E/MediaPlayer:应已设置字幕控制器 下面是示例中的一段代码Android studio 此处地图中的语音说明不起作用,android-studio,here-api,Android Studio,Here Api,我想通过Android上的HERE Maps实现语音指令,我使用了示例代码“LiveSightGuidanceActivity”,并从中添加了与语音指令相关的代码 但是声音不起作用!我发现了错误 E/MediaPlayer:应已设置字幕控制器 下面是示例中的一段代码 // Setup navigation manager m_navigationManager = NavigationManager.getInstance(); m_navigationMan
// Setup navigation manager
m_navigationManager = NavigationManager.getInstance();
m_navigationManager.setMap(m_map);
m_navigationManager.setMapUpdateMode(MapUpdateMode.NONE); // No need to update map as LiveSight already does so
attachNavigationListeners();
stopNavigationManager();
// Disable navigation sounds
m_audioFlags = m_navigationManager.getEnabledAudioEvents();
m_navigationManager.setEnabledAudioEvents(EnumSet.allOf((NavigationManager.AudioEvent.class))); // it was nonOf
// Disable traffic avoidance mode as we use pedestrian guidance
m_navigationManager.setTrafficAvoidanceMode(TrafficAvoidanceMode.DISABLE);
// Start navigation in Simulation Mode
NavigationManager.Error error = m_navigationManager.simulate(m_liveSightMapRoute.getRoute(), SIMULATION_SPEED);
if (error != NavigationManager.Error.NONE) {
Toast.makeText(getApplicationContext(), "Failed to start navigation. Error: " + error, Toast.LENGTH_LONG).show();
m_navigationManager.setMap(null);
return;
}
m_navigationManager.setNaturalGuidanceMode(EnumSet.of(NavigationManager.NaturalGuidanceMode.JUNCTION));
setupVoice();
下面是完整的setupVoice()方法
private void setupVoice(){
//声明听众
//在每个回调中添加特定于应用程序的逻辑。
instructListener=new NavigationManager.NewInstructionEventListener(){
@凌驾
公共结构事件(){
//解释并呈现包含的机动对象
//针对用户的逐段导航说明。
m_navigationManager.getNextManeuver();
}
};
positionListener=new NavigationManager.positionListener(){
@凌驾
已更新公共位置(地理位置loc){
//我们在这个回调中得到的位置可以使用
//重新定位地图并更改方向的步骤。
loc.getCoordinate();
loc.getHeading();
loc.getSpeed();
//另外,剩余的时间和距离也可以
//从导航管理器获取
m_navigationManager.getTimeOarRival(对,
路线。交通处罚模式(禁用);
m_navigationManager.getDestinationDistance();
}
};
//开始收听导航事件
m_navigationManager.addNewInstructionEventListener(
新WeakReference(instructListener));
//开始收听位置事件
m_navigationManager.addPositionListener(
新WeakReference(positionListener));
//检索VoiceCatalog并下载最新更新
VoiceCatalog=VoiceCatalog.getInstance();
如果(!voiceCatalog.isLocalCatalogAvailable()){
Log.d(标记“语音目录在本地存储中不可用”);
//Toast.makeText(mActivity.getApplicationContext(),“语音目录在本地存储中不可用。”,Toast.LENGTH_LONG).show();
下载目录(new voiceCatalog.OnDownloadDoneListener(){
@凌驾
公共无效onDownloadDone(VoiceCatalog.Error){
if(error==VoiceCatalog.error.NONE){
//目录下载成功
Log.d(标记“成功下载语音目录”);
//Toast.makeText(mActivity.getApplicationContext(),“语音目录下载成功”,Toast.LENGTH\u LONG.show();
}否则{
Log.d(标记“下载语音目录失败”);
//Toast.makeText(mActivity.getApplicationContext(),“语音目录下载错误”,Toast.LENGTH_LONG).show();
}
//从语音目录列表中获取语音包列表
列出语音包=
VoiceCatalog.getInstance().getCatalogList();
if(voicePackages.size()==0){
Log.d(标记“语音目录大小为0”);
//Toast.makeText(mActivity.getApplicationContext(),“语音目录大小为0.”,Toast.LENGTH_LONG.show();
}
长id=-1;
//挑选
用于(语音包语音包:语音包){
if(voicePackage.getMarcCode().compareToIgnoreCase(“eng”)==0){
if(voicePackage.isTts())//TODO:需要弄清楚为什么总是返回false
{
id=voicePackage.getId();
打破
}
}
}
如果(!VoiceCatalog.getInstance().isLocalVoiceSkin(id)){
最终长finalId=id;
VoiceCatalog.getInstance().downloadVoice(id,new VoiceCatalog.OnDownloadDoneListener()){
@凌驾
公共无效onDownloadDone(VoiceCatalog.Error){
if(error==VoiceCatalog.error.NONE){
//语音皮肤下载成功
Log.d(标记“成功下载语音皮肤”);
//Toast.makeText(mActivity.getApplicationContext(),“Voice skin下载成功”,Toast.LENGTH_LONG.show();
//设置语音外观以供导航管理器使用
if(VoiceCatalog.getInstance().getLocalVoiceSkin(finalId)!=null){
m_navigationManager.setVoiceSkin(VoiceCatalog.getInstance().getLocalVoiceSkin(finalId));
}否则{
Log.d(标记“获取本地语音皮肤错误”);
//Toast.makeText(mActivity.getApplicationContext(),“Navi管理器设置语音皮肤错误”,Toast.LENGTH_LONG).show();
}
}否则{
Log.d(标签“下载语音皮肤失败”);
//Toast.makeText(mActivity.getApplicationContext(),“语音皮肤下载错误”,Toast.LENGTH_LONG.show();
}
}
});
}否则{
//设置语音外观以供导航管理器使用
private void setupVoice() {
// declare the listeners
// add application specific logic in each of the callbacks.
instructListener = new NavigationManager.NewInstructionEventListener() {
@Override
public void onNewInstructionEvent() {
// Interpret and present the Maneuver object as it contains
// turn by turn navigation instructions for the user.
m_navigationManager.getNextManeuver();
}
};
positionListener = new NavigationManager.PositionListener() {
@Override
public void onPositionUpdated(GeoPosition loc) {
// the position we get in this callback can be used
// to reposition the map and change orientation.
loc.getCoordinate();
loc.getHeading();
loc.getSpeed();
// also remaining time and distance can be
// fetched from navigation manager
m_navigationManager.getTimeToArrival(true,
Route.TrafficPenaltyMode.DISABLED);
m_navigationManager.getDestinationDistance();
}
};
// start listening to navigation events
m_navigationManager.addNewInstructionEventListener(
new WeakReference<NavigationManager.NewInstructionEventListener>(instructListener));
// start listening to position events
m_navigationManager.addPositionListener(
new WeakReference<NavigationManager.PositionListener>(positionListener));
// Retrieve the VoiceCatalog and download the latest updates
VoiceCatalog voiceCatalog = VoiceCatalog.getInstance();
if (!voiceCatalog.isLocalCatalogAvailable()) {
Log.d(TAG, "Voice catalog is not available in local storage.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice catalog is not available in local storage.", Toast.LENGTH_LONG).show();
voiceCatalog.downloadCatalog(new VoiceCatalog.OnDownloadDoneListener() {
@Override
public void onDownloadDone(VoiceCatalog.Error error) {
if (error == VoiceCatalog.Error.NONE) {
// catalog download successful
Log.d(TAG, "Download voice catalog successfully.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice catalog download successful.", Toast.LENGTH_LONG).show();
} else {
Log.d(TAG, "Download voice catalog failed.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice catalog download error.", Toast.LENGTH_LONG).show();
}
// Get the list of voice packages from the voice catalog list
List<VoicePackage> voicePackages =
VoiceCatalog.getInstance().getCatalogList();
if (voicePackages.size() == 0) {
Log.d(TAG, "Voice catalog size is 0.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice catalog size is 0.", Toast.LENGTH_LONG).show();
}
long id = -1;
// select
for (VoicePackage voicePackage : voicePackages) {
if (voicePackage.getMarcCode().compareToIgnoreCase("eng") == 0) {
if (voicePackage.isTts()) // TODO: need to figure out why always return false
{
id = voicePackage.getId();
break;
}
}
}
if (!VoiceCatalog.getInstance().isLocalVoiceSkin(id)) {
final long finalId = id;
VoiceCatalog.getInstance().downloadVoice(id, new VoiceCatalog.OnDownloadDoneListener() {
@Override
public void onDownloadDone(VoiceCatalog.Error error) {
if (error == VoiceCatalog.Error.NONE) {
//voice skin download successful
Log.d(TAG, "Download voice skin successfully.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice skin download successful.", Toast.LENGTH_LONG).show();
// set the voice skin for use by navigation manager
if (VoiceCatalog.getInstance().getLocalVoiceSkin(finalId) != null) {
m_navigationManager.setVoiceSkin(VoiceCatalog.getInstance().getLocalVoiceSkin(finalId));
} else {
Log.d(TAG, "Get local voice skin error.");
//Toast.makeText(mActivity.getApplicationContext(), "Navi manager set voice skin error.", Toast.LENGTH_LONG).show();
}
} else {
Log.d(TAG, "Download voice skin failed.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice skin download error.", Toast.LENGTH_LONG).show();
}
}
});
} else {
// set the voice skin for use by navigation manager
if (VoiceCatalog.getInstance().getLocalVoiceSkin(id) != null) {
m_navigationManager.setVoiceSkin(VoiceCatalog.getInstance().getLocalVoiceSkin(id));
} else {
Log.d(TAG, "Get local voice skin error.");
//Toast.makeText(mActivity.getApplicationContext(), "Navi manager set voice skin error.", Toast.LENGTH_LONG).show();
}
}
}
});
}
}
List localInstalledSkins = VoiceCatalog.getInstance().getLocalVoiceSkins();
VoiceCatalog.getInstance().downloadCatalog(VoiceCatalog.OnDownloadDoneListener)
List packages = VoiceCatalog.getInstance().getCatalogList();
VoiceCatalog.getInstance().downloadVoice(skin_id_from_catalog_you_want_to_use, VoiceCatalog.OnDownloadDoneListener)
NavigationManager.getInstance().setVoiceSkin(VoiceCatalog.getInstance().getLocalVoiceSkin(skin_id_you_want_to_use))