简体   繁体   English

将播放框架路由转换为Java URL类(用于初始化java.net.URL类)

[英]convert play framework route to java URL class (used to initialize java.net.URL class)

I want to play song in page when it opening. 我想在打开时在页面中播放歌曲。 (I know It's a bad idea but I want to say Happy Birthday to my cousins :D ) for that I need to convert play framework routes to java.net.URL class. (我知道这是个坏主意,但我想对我的表弟说:D生日快乐),因为我需要将播放框架路由转换为java.net.URL类。 I tried these line of code but all of them gave me NULL pointer 我尝试了这些代码行,但所有这些都给了我NULL指针

URL url = app.getClass().getClassLoader().getResource( 
    "../../public/sounds/9-Baroon.wav");

URL url = app.getClass().getClassLoader().getResource(
    controllers.routes.Assets.at("sounds/9-Baroon.wav").absoluteURL(request()));

URL url = app.getClass().getClassLoader().getResource( 
    controllers.routes.Assets.at("sounds/9-Baroon.wav");

how can I get that music file? 我如何获取音乐文件?

Some word 有些话

I'm stupid. 我真笨。 I think I had to use controller for playing sound but this must done in views. 我认为我必须使用控制器来播放声音,但这必须在视图中完成。 I don't remove this question because anyone make that mistake find his/her mistake sooner. 我不会删除此问题,因为任何犯此错误的人都会早日发现自己的错误。

It has nothing to do with Play Framework. 它与Play框架无关。 You want to play sound on the webpage directly from HTML (or with some Javascript). 您想直接从HTML(或使用某些Javascript)在网页上播放声音。

So you don't need Java for it (though your still can serve your .wav file from Play Framework as static asset). 因此,您不需要Java(尽管您仍然可以将Play框架中的.wav文件用作静态资产)。

Check these links: w3schools.com/html/html5_audio.asp or stackoverflow.com/a/13402388/972676 . 检查以下链接: w3schools.com/html/html5_audio.aspstackoverflow.com/a/13402388/972676

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM