如何在Angular中插入HTML5音频/视频自动播放标记

时间:2014-06-10 22:04:04

标签: javascript angularjs html5-video html5-audio google-translate

我正在尝试将AngularJS用于个人项目。

这个想法是生成一个数字(或更晚的单词),并让Google翻译的文字转语音网址进行阅读。然后你必须写下所说的内容。

我成功地使其有效,但我不知道发生了什么,它不再起作用了。

以下是该项目的链接: https://github.com/Polopollo/numberProject

这是给我带来一些问题的文件: https://github.com/Polopollo/numberProject/blob/master/app/scripts/services/soundgenerator.js

我在这里复制内容:

'use strict';

angular.module('languageTrainerApp').provider('soundgenerator', function(){

//in case of we want to change the API to generate a sound file from a text
this.defaultTextToSpeechUrl = 'http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=';

this.$get = function() {
    //to escape the error to be able to write on multiple lines
    /*jshint multistr: true */

    //here is our service which will have a method to generate the player to insert
    var soundgenerator = {
        'generatePlayer': function (textToRead) {
            var res = '\
                <audio controls autoplay>\
                  <source src="https://translate.google.com/translate_tts?ie=UTF-8&tl=en&q='+textToRead+'" type="audio/mpeg">\
                  Your browser does not support the audio element.\
                </audio>';
            return res;
        }
    };

    return soundgenerator;
    };
});

我尝试将其注入&#34; main.js&#34;:

//why this doesn't work..?
$scope.HTML5AudioPlayer = $sce.trustAsHtml(soundgenerator.generatePlayer("A text to read"));

我想获得有关错误内容的所有信息,包括如果编写得不好我应该如何编写提供程序,但主要是为了使音频播放器正常工作!

0 个答案:

没有答案