Gluon-Mobile应用程序没有声音

时间:2018-12-23 19:20:15

标签: java javafx gluon-mobile

我正在使用YouTube播放器,并使用JavaFX WebView和YouTube-Embedded_Player播放视频。
直到我切换到Gluon-Mobile(相关代码未更改),此方法才能正常工作。现在,如果我要播放视频,则视频正在显示,但是没有声音(我也测试了播放声音文件的机制,但是存在相同的问题)。 奇怪的是:在Windows的混音器中,该应用程序已列出并且声音已可视化,但我听不到任何声音。我在另一台计算机上测试了该应用程序,并且该应用程序正常工作。
JDK:1.8(x64)

代码:

public class PlayerPresenter extends GluonPresenter<Main> implements Initializable{
   private static final String PLAYER_HTML = Context.class.getResource("videoContainer.html").toString();
   [...]
   @FXML private View view;
   @FXML private WebView webView;
   [...]
   @Override
   public void initialize(URL location, ResourceBundle resources){
      webView.getEngine().load(PLAYER_HTML);
   }
   [...]
   private void play(){
      webView.getEngine().executeScript("playVideo('" + video.id + "', '" + video.type.name() + "')");
      // video is an instance from a class which holds informations about a YouTube video / playlist
   }
   [...]
}

videoConatiner.html:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8;charset=utf-8"/>
    <script type="text/javascript" src="videoControl.js"></script>
    <style>
        html, body{
            height: 100%;
            width: 100%;
            overflow-x: hidden;
            overflow-y: hidden;
            margin: auto;
        }
    </style>
</head>
<body>
<div id="player"></div>
</body>
</html>

videoControl.js

var player;
var id;
var mode;
var ready = false;
var onReady = null;

setUp();

function setUp(){
    this.ready = false;
    var tag = document.createElement('script');
    tag.src = "https://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
        height: "100%",
        width: "100%",
        events: {
           'onReady': onPlayerReady,
           'onStateChange': onPlayerStateChange
        },
        playerVars: {
            fs: 0,
            rel: 0
        }
    });
}

function onPlayerReady(event) {
    this.ready = true;
    if(this.onReady != null) this.onReady();
}
function onPlayerStateChange(event) {
    if (event.data == YT.PlayerState.PLAYING) {
        var videoData = player.getVideoData();
        this.id = videoData.video_id;
    }
}

function playVideo(id, type){
    if(!isReady()){
        this.onReady = function (){
            this.onReady = null;
            playVideo0(id, type);
        }
    }else{
        playVideo0(id, type);
    }
    return null;
}
function playVideo0(id, type){
    this.id = id;
    this.mode = type;

    switch (mode){
        case "VIDEO":
            player.loadVideoById({
                videoId:id
            });
            break;
        case "PLAYLIST":
            player.loadPlaylist({
                list:id,
                listType:"playlist",
                index:0
           });
           break;
    }
    return null;
}
function stop(){
    player.stopVideo();
}
function getVideoId(){
    return this.id;
}
function isReady(){
    return this.ready;
}

所以我的问题是:这是我的应用程序中的错误还是计算机导致了问题(以及如何解决此问题)。
感谢您的帮助。

0 个答案:

没有答案