Search in sources :

Example 1 with MediaCommandPlayerImpl

use of net.osmand.plus.voice.MediaCommandPlayerImpl in project Osmand by osmandapp.

the class AppInitializer method initVoiceDataInDifferentThread.

public synchronized void initVoiceDataInDifferentThread(final Activity uiContext, final ApplicationMode applicationMode, final String voiceProvider, final Runnable run, boolean showDialog) {
    final ProgressDialog dlg = showDialog ? ProgressDialog.show(uiContext, app.getString(R.string.loading_data), app.getString(R.string.voice_data_initializing)) : null;
    new Thread(new Runnable() {

        public CommandPlayer createCommandPlayer(String voiceProvider, ApplicationMode applicationMode, OsmandApplication osmandApplication, Activity ctx) throws CommandPlayerException {
            if (voiceProvider != null) {
                File parent = osmandApplication.getAppPath(IndexConstants.VOICE_INDEX_DIR);
                File voiceDir = new File(parent, voiceProvider);
                if (!voiceDir.exists()) {
                    throw new CommandPlayerException(ctx.getString(R.string.voice_data_unavailable));
                }
                if (MediaCommandPlayerImpl.isMyData(voiceDir)) {
                    return new MediaCommandPlayerImpl(osmandApplication, applicationMode, osmandApplication.getRoutingHelper().getVoiceRouter(), voiceProvider);
                } else if (TTSCommandPlayerImpl.isMyData(voiceDir)) {
                    return new TTSCommandPlayerImpl(ctx, applicationMode, osmandApplication.getRoutingHelper().getVoiceRouter(), voiceProvider);
                }
                throw new CommandPlayerException(ctx.getString(R.string.voice_data_not_supported));
            }
            return null;
        }

        @Override
        public void run() {
            try {
                if (app.player != null) {
                    app.player.clear();
                }
                app.player = createCommandPlayer(voiceProvider, applicationMode, app, uiContext);
                app.getRoutingHelper().getVoiceRouter().setPlayer(app.player);
                if (dlg != null) {
                    dlg.dismiss();
                }
                if (run != null && uiContext != null) {
                    uiContext.runOnUiThread(run);
                }
            } catch (CommandPlayerException e) {
                if (dlg != null) {
                    dlg.dismiss();
                }
                app.showToastMessage(e.getError());
            }
        }
    }).start();
}
Also used : MediaCommandPlayerImpl(net.osmand.plus.voice.MediaCommandPlayerImpl) CommandPlayerException(net.osmand.plus.voice.CommandPlayerException) DownloadActivity(net.osmand.plus.download.DownloadActivity) Activity(android.app.Activity) ProgressDialog(android.app.ProgressDialog) File(java.io.File) TTSCommandPlayerImpl(net.osmand.plus.voice.TTSCommandPlayerImpl)

Aggregations

Activity (android.app.Activity)1 ProgressDialog (android.app.ProgressDialog)1 File (java.io.File)1 DownloadActivity (net.osmand.plus.download.DownloadActivity)1 CommandPlayerException (net.osmand.plus.voice.CommandPlayerException)1 MediaCommandPlayerImpl (net.osmand.plus.voice.MediaCommandPlayerImpl)1 TTSCommandPlayerImpl (net.osmand.plus.voice.TTSCommandPlayerImpl)1