首页 \ 问答 \ 头部的Angular Dynamic meta标签(Angular Dynamic meta tags in head)

头部的Angular Dynamic meta标签(Angular Dynamic meta tags in head)

我需要在角度应用程序的特定页面上插入打开的图形元标记。

这些标签根据页面所具有的新闻或视频而不同。

我试图向$ rootscope添加一个变量。 这个变量在相关时会被元标记填充。

现在这是我的问题。 只要这个变量被HTML字符串填充,它们不会构成头部的一部分,而是输出到身体。 我搜索了一天,找不到任何可行的解决方案。 任何帮助,将不胜感激


I need to insert open graph meta tags on a particular page in an angular app.

These tags are different based on the news or video that the page has.

I tried adding a variable to the $rootscope. This variable will be populated with the meta tags when it is relevant.

Now here is my issue. As soon as this variable gets populated with the HTML string, they don't form a part of the head and are instead outputted to the body. I have searched for a day and could not find any viable solutions. Any help would be appreciated


原文:https://stackoverflow.com/questions/27381918
更新时间:2022-05-07 11:05

最满意答案

终于在我挠了头两天之后我终于做到了。 对于那些想要实现这样的但却无法实现的人来说,这里是代码

public void speak(final String talk) throws InterruptedException {
    final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    int ringVolume = audioManager
            .getStreamVolume(AudioManager.STREAM_RING);
    int musicVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    currentRingVolume = ringVolume;

    musicVolume = (int) ((musicVolume * seekbarValue) / 100);

    if (PauseRingtone == true) {
        audioManager.setStreamVolume(AudioManager.STREAM_RING, 1,
                AudioManager.FLAG_SHOW_UI);
    } else {
        audioManager.setStreamVolume(AudioManager.STREAM_RING,
                ringVolume, AudioManager.FLAG_SHOW_UI);
    }

    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicVolume, 0);

    int result = tts
            .setOnUtteranceProgressListener(new UtteranceProgressListener() {

                @Override
                public void onStart(String utteranceId) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onError(String utteranceId) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onDone(String utteranceId) {
                    // TODO Auto-generated method stub
                    System.out.println("done");
                    audioManager.setStreamVolume(AudioManager.STREAM_RING,
                            currentRingVolume, 0);
                }
            });
    HashMap<String, String> params = new HashMap<String, String>();
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "stringId");
    tts.speak(talk, TextToSpeech.QUEUE_FLUSH, params);
    System.out.println("speaking after tts is over" + talk + " " + result);

}

解释: -

ringVolume - 获取手机中设置的铃声 .ie铃声音量的当前音量。

musicVolume - 获取当前音乐的音量

currentRingVolume只保留ringVolume

注意 - STREAM_RINGSTREAM_MUSIC是不同的东西。 看到 不同的卷

现在基本的想法是在TTS讲话时将ringtone mute ,然后将其设置为之前的值。

seekBarValue - 是我的SeekBar ,它描绘了音乐音量的TTS音量,是可选的。

PauseRingtone - 是一个CheckBox Preference ,用于检查我们是否要在讲话时暂停铃声。 如果为true则将AudioManager.STREAM_RING设置为1vibrate其他ringVolumePhone Value ,因此TTSRingtone播放。

audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,musicVolume, 0) 

TTS的音量设置为musicVolume 。 在TTS完成发言之后,即在onDone()我们使用currentRingVolumeRingtone的音量设置回ringVolume

如果我的回答有助于标记我的答案有用。


Finally after scratching my head for two days i finally did it. For all those who want to implement something like this but are unable to do so here is the code

public void speak(final String talk) throws InterruptedException {
    final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    int ringVolume = audioManager
            .getStreamVolume(AudioManager.STREAM_RING);
    int musicVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    currentRingVolume = ringVolume;

    musicVolume = (int) ((musicVolume * seekbarValue) / 100);

    if (PauseRingtone == true) {
        audioManager.setStreamVolume(AudioManager.STREAM_RING, 1,
                AudioManager.FLAG_SHOW_UI);
    } else {
        audioManager.setStreamVolume(AudioManager.STREAM_RING,
                ringVolume, AudioManager.FLAG_SHOW_UI);
    }

    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicVolume, 0);

    int result = tts
            .setOnUtteranceProgressListener(new UtteranceProgressListener() {

                @Override
                public void onStart(String utteranceId) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onError(String utteranceId) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onDone(String utteranceId) {
                    // TODO Auto-generated method stub
                    System.out.println("done");
                    audioManager.setStreamVolume(AudioManager.STREAM_RING,
                            currentRingVolume, 0);
                }
            });
    HashMap<String, String> params = new HashMap<String, String>();
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "stringId");
    tts.speak(talk, TextToSpeech.QUEUE_FLUSH, params);
    System.out.println("speaking after tts is over" + talk + " " + result);

}

explaination :-

ringVolume - gets the current volume of the ringtone .i.e ringtone volume set in the phone.

musicVolume - gets the current volume of the music

currentRingVolume just retains the ringVolume.

Note- STREAM_RING and STREAM_MUSIC are different things. See different volumes

Now the basic idea is to mute the ringtone while TTS is speaking and then set it to previous value.

seekBarValue- is my SeekBar which depicts the level of the TTS volume w.r.t musicVolume and is optional.

PauseRingtone- is a CheckBox Preference which checks whether we want to pause ringtone while speaking. If true is sets the AudioManager.STREAM_RING to 1 i.e. vibrate else ringVolume i.e. Phone Value, so both TTS and Ringtone play at the same time.

audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,musicVolume, 0) 

sets the volume of TTS to musicVolume. After TTS has completed speaking i.e. in onDone() we set the volume of Ringtone back to the ringVolume using currentRingVolume.

If my answer helped mark my answer useful.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。