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. I tried these line of code but all of them gave me NULL pointer
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?
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. You want to play sound on the webpage directly from HTML (or with some Javascript).
So you don't need Java for it (though your still can serve your .wav
file from Play Framework as static asset).
Check these links: w3schools.com/html/html5_audio.asp or stackoverflow.com/a/13402388/972676 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.