essential-actions
Clone or download
Modified Files
M
playaudioclipaction/src/main/java/com/stream_pi/playaudioclipaction/PlayAudioClipAction.java
+9
−8
package com.stream_pi.playaudioclipaction;
package com.stream_pi.playaudioclipaction;
import com.stream_pi.action_api.actionproperty.property.ControlType;
import com.stream_pi.action_api.actionproperty.property.ControlType;
import com.stream_pi.action_api.actionproperty.property.FileExtensionFilter;
import com.stream_pi.action_api.actionproperty.property.FileExtensionFilter;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.scene.media.AudioClip;
import javafx.scene.media.AudioClip;
import java.io.File;
import java.io.File;
public class PlayAudioClipAction extends NormalAction {
public class PlayAudioClipAction extends NormalAction {
public PlayAudioClipAction()
public PlayAudioClipAction()
{
{
setName("Play Audio Clip");
setName("Play Audio Clip");
setCategory("Essentials");
setCategory("Essentials");
setAuthor("rnayabed");
setAuthor("rnayabed");
setServerButtonGraphic("fas-volume-up");
setServerButtonGraphic("fas-volume-up");
setHelpLink("https://github.com/Stream-Pi/EssentialActions");
setHelpLink("https://github.com/Stream-Pi/EssentialActions");
setVersion(new Version(2,0,0));
setVersion(new Version(2,0,0));
}
}
@Override
@Override
public void initProperties() throws Exception
public void initProperties() throws Exception
{
{
Property audioFileLocationProperty = new Property("audio_location", Type.STRING);
Property audioFileLocationProperty = new Property("audio_location", Type.STRING);
audioFileLocationProperty.setControlType(ControlType.FILE_PATH);
audioFileLocationProperty.setControlType(ControlType.FILE_PATH);
audioFileLocationProperty.setDisplayName("Audio File Location");
audioFileLocationProperty.setDisplayName("Audio File Location");
audioFileLocationProperty.setExtensionFilters(
audioFileLocationProperty.setExtensionFilters(
new FileExtensionFilter("MP3","*.mp3"),
new FileExtensionFilter("MP3","*.mp3"),
new FileExtensionFilter("MP4","*.mp4", "*.m4a", "*.m4v"),
new FileExtensionFilter("MP4","*.mp4", "*.m4a", "*.m4v"),
new FileExtensionFilter("WAV","*.wav"),
new FileExtensionFilter("WAV","*.wav"),
new FileExtensionFilter("AIFF","*.aif", "*.aiff"),
new FileExtensionFilter("AIFF","*.aif", "*.aiff"),
new FileExtensionFilter("FXM","*.fxm"),
new FileExtensionFilter("FXM","*.fxm"),
new FileExtensionFilter("FLV","*.flv"),
new FileExtensionFilter("FLV","*.flv"),
new FileExtensionFilter("HLS","*.m3u8")
new FileExtensionFilter("HLS","*.m3u8")
);
);
addClientProperties(audioFileLocationProperty);
addClientProperties(audioFileLocationProperty);
}
}
public AudioClip mediaPlayer = null;
public AudioClip mediaPlayer = null;
public String path = null;
public String path = null;
@Override
@Override
public void onActionClicked() throws Exception
public void onActionClicked() throws Exception
{
{
Property audioFileLocationProperty = getClientProperties().getSingleProperty("audio_location");
Property audioFileLocationProperty = getClientProperties().getSingleProperty("audio_location");
if (audioFileLocationProperty.getStringValue().isBlank())
if (audioFileLocationProperty.getStringValue().isBlank())
{
{
new StreamPiAlert("Media Action", "No file specified", StreamPiAlertType.ERROR).show();
new StreamPiAlert("Media Action", "No file specified", StreamPiAlertType.ERROR).show();
return;
return;
}
}
if(!path.equals(audioFileLocationProperty.getStringValue()))
if(mediaPlayer != null)
{
{
if(mediaPlayer!=null)
if(mediaPlayer.isPlaying())
{
{
if(mediaPlayer.isPlaying())
Platform.runLater(mediaPlayer::stop);
Platform.runLater(mediaPlayer::stop);
return;
}
}
}
if(!audioFileLocationProperty.getStringValue().equals(path))
{
path = audioFileLocationProperty.getStringValue();
path = audioFileLocationProperty.getStringValue();
mediaPlayer = new AudioClip(new File(path).toURI().toString());
mediaPlayer = new AudioClip(new File(path).toURI().toString());
}
}
if(mediaPlayer.isPlaying())
Platform.runLater(mediaPlayer::play);
Platform.runLater(mediaPlayer::stop);
else
Platform.runLater(mediaPlayer::play);
}
}
@Override
@Override
public void onShutDown()
public void onShutDown()
{
{
if(mediaPlayer.isPlaying())
if(mediaPlayer.isPlaying())
Platform.runLater(mediaPlayer::stop);
Platform.runLater(mediaPlayer::stop);
}
}
}
}