playStream: Difference between revisions
No edit summary |
mNo edit summary |
||
(22 intermediate revisions by 6 users not shown) | |||
Line 3: | Line 3: | ||
|version=1.5.5 | |version=1.5.5 | ||
|description= | |description= | ||
Play an audio stream for the current player, from an online source or from a local file. Can be disabled in the sound preferences. Multiple files can be played at the same time. If attempting to play the same audio file twice, the previous streaming is stopped. | Play an audio stream for the current player, from an online source or from a local file. Can be disabled in the sound preferences. Multiple files can be played at the same time. If attempting to play the same audio file twice, the previous streaming is stopped. Supports AIFF, MP3 and Wave formats.<br> | ||
<br> | |||
'''Known Issues:''' Currently a bug in the underlying JavaFX code makes the cycle count unreliable. Audio clips will often play some number of times less than the requested count. This will be fixed when a new JavaFX version is incorporated. | |||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
playStream(uri) | playStream(uri) | ||
playStream(uri, cycleCount) | playStream(uri, cycleCount) | ||
Line 12: | Line 14: | ||
playStream(uri, cycleCount, volume, start) | playStream(uri, cycleCount, volume, start) | ||
playStream(uri, cycleCount, volume, start, stop) | playStream(uri, cycleCount, volume, start, stop) | ||
</ | </syntaxhighlight> | ||
'''Parameter''' | '''Parameter''' | ||
{{param|uri|The uri/url of the file, | {{param|uri|The uri/url of the file. For example, http://www.mywebsite/mysong.mp3 or {{code|file:/C:/mysong.mp3}} }} | ||
{{param|cycleCount|The number of times the audio should play. If set to 0, the file is cached but not played; if set to -1, the file is played continuously. Defaults to 1.}} | {{param|cycleCount|The number of times the audio should play. If set to 0, the file is cached but not played; if set to -1, the file is played continuously. Defaults to 1.}} | ||
{{param|volume|The volume the audio is to be played at. Can range from 0 to 1. Defaults to 1.}} | {{param|volume|The volume the audio is to be played at. Can range from 0 to 1. Defaults to 1.}} | ||
{{param|start|The time offset in seconds where audio should start playing, or restart from when repeating. Defaults to 0.}} | {{param|start|The time offset in seconds where audio should start playing, or restart from when repeating. Defaults to 0.}} | ||
{{param|stop|The time offset where audio should stop playing or restart when repeating. Defaults to the end of the audio.}} | {{param|stop|The time offset where audio should stop playing or restart when repeating. Defaults to the end of the audio.}} | ||
|examples= | |||
To play a song from an online source to all clients, the GM can create the macro "playSong" on a Lib token, say, "Lib:MusicPlayer": | |||
<syntaxhighlight lang="mtmacro" line> | |||
[playStream(macro.args)] | |||
</syntaxhighlight> | |||
To play the song, the GM can then use [[execLink]]: | |||
<syntaxhighlight lang="mtmacro" line> | |||
[H: songUrl = "http://erinmcnamee.com.hostbaby.com/files/07_No_Sorrow__Banish_Misfortune.mp3"] | |||
[H: audioByte = macroLinkText("playSong@Lib:MusicPlayer", "none", songUrl)] | |||
[H: execLink(audioByte,0,"all")] | |||
</syntaxhighlight> | |||
Alternatively, the GM can use [[execFunction]]: | |||
<syntaxhighlight lang="mtmacro" line> | |||
[H: songUrl = json.append("[]","http://erinmcnamee.com.hostbaby.com/files/07_No_Sorrow__Banish_Misfortune.mp3")] | |||
[H: execFunction("playStream", songUrl, 0, "all") | |||
</syntaxhighlight> | |||
== Dropbox URLs == | |||
After creating the dropbox share link you have to replace www.dropbox.com with dl.dropboxusercontent.com. That provides a direct link that playStream can use. Thanks to Full Bleed on the forums for the tip. | |||
Also note that dropbox no longer supports the "http" protocol, and only supports "https". If the "s" is omitted, the sound will not play. | |||
As if 9/1/23 new dropbox files have a different format and can no longer be converted to allow playStream to work. The url link needs to end in .mp3 or other valid file type. An alternate method is to now use a Discord server to file host and copy the link from the post. | |||
== Technical Info == | |||
The JavaFX docs provide more information about the supported media types. The MapTool macro functions only support the audio types. | |||
[[https://docs.oracle.com/javase/10/docs/api/index.html?javafx/scene/media/package-summary.html JavaFX Media Package]] | |||
}} | }} | ||
[[Category:Audio Function]] | [[Category:Audio Function]] |
Latest revision as of 23:59, 11 September 2023
playStream() Function
Usage
playStream(uri)
playStream(uri, cycleCount)
playStream(uri, cycleCount, volume)
playStream(uri, cycleCount, volume, start)
playStream(uri, cycleCount, volume, start, stop)
Parameter
uri
- The uri/url of the file. For example, http://www.mywebsite/mysong.mp3 orfile:/C:/mysong.mp3
cycleCount
- The number of times the audio should play. If set to 0, the file is cached but not played; if set to -1, the file is played continuously. Defaults to 1.volume
- The volume the audio is to be played at. Can range from 0 to 1. Defaults to 1.start
- The time offset in seconds where audio should start playing, or restart from when repeating. Defaults to 0.stop
- The time offset where audio should stop playing or restart when repeating. Defaults to the end of the audio.
Examples
[playStream(macro.args)]
To play the song, the GM can then use execLink:
[H: songUrl = "http://erinmcnamee.com.hostbaby.com/files/07_No_Sorrow__Banish_Misfortune.mp3"]
[H: audioByte = macroLinkText("playSong@Lib:MusicPlayer", "none", songUrl)]
[H: execLink(audioByte,0,"all")]
Alternatively, the GM can use execFunction:
[H: songUrl = json.append("[]","http://erinmcnamee.com.hostbaby.com/files/07_No_Sorrow__Banish_Misfortune.mp3")]
[H: execFunction("playStream", songUrl, 0, "all")
Dropbox URLs
After creating the dropbox share link you have to replace www.dropbox.com with dl.dropboxusercontent.com. That provides a direct link that playStream can use. Thanks to Full Bleed on the forums for the tip.
Also note that dropbox no longer supports the "http" protocol, and only supports "https". If the "s" is omitted, the sound will not play.
As if 9/1/23 new dropbox files have a different format and can no longer be converted to allow playStream to work. The url link needs to end in .mp3 or other valid file type. An alternate method is to now use a Discord server to file host and copy the link from the post.
Technical Info
The JavaFX docs provide more information about the supported media types. The MapTool macro functions only support the audio types.
[JavaFX Media Package]