Merge pull request #11 from YosefJoo/master

Initially ،add PlayMode 🥰
This commit is contained in:
Anas Elgarhy 2023-01-15 21:59:00 +02:00 committed by GitHub
commit d34b32db8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,8 @@
package com.anas.intellij.plugins.ayah; package com.anas.intellij.plugins.ayah;
import com.anas.alqurancloudapi.Ayah; import com.anas.alqurancloudapi.Ayah;
import com.anas.alqurancloudapi.edition.Edition;
import com.anas.alqurancloudapi.edition.EditionFormat;
import com.anas.intellij.plugins.ayah.audio.AudioPlayer; import com.anas.intellij.plugins.ayah.audio.AudioPlayer;
import com.anas.intellij.plugins.ayah.audio.PlayerListener; import com.anas.intellij.plugins.ayah.audio.PlayerListener;
import com.anas.intellij.plugins.ayah.dialogs.AyahDetailsDialog; import com.anas.intellij.plugins.ayah.dialogs.AyahDetailsDialog;
@ -29,6 +31,8 @@ public class NotificationTimerTask extends TimerTask implements PlayerListener {
private AudioPlayer audioPlayer; private AudioPlayer audioPlayer;
private boolean isPlaying; private boolean isPlaying;
private Ayah ayah; private Ayah ayah;
private Ayah currentAyah; // current ayah
private AudioPlayer player;
@Override @Override
@ -69,6 +73,12 @@ public class NotificationTimerTask extends TimerTask implements PlayerListener {
new AyahDetailsDialog(ayah).setVisible(true); new AyahDetailsDialog(ayah).setVisible(true);
} }
}); });
notification.addAction(new AnAction("PlayMode") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
playMode();
}
});
// Show notification // Show notification
notification.notify(project); notification.notify(project);
@ -77,6 +87,7 @@ public class NotificationTimerTask extends TimerTask implements PlayerListener {
} }
} }
public void setProject(final Project project) { public void setProject(final Project project) {
this.project = project; this.project = project;
} }
@ -100,6 +111,16 @@ public class NotificationTimerTask extends TimerTask implements PlayerListener {
} }
} }
} }
public void playMode(){
try{
final var currentEdition= Edition.getEditions(EditionFormat.AUDIO,"ar",null);
currentAyah=Ayah.getAyah(1,currentEdition[0]);
player=new AudioPlayer(currentAyah.getAudioUrl()).setListener(this);
player.play();
} catch (IOException e) {
e.printStackTrace();
}
}
// Player listener methods. // Player listener methods.
@Override @Override
@ -110,5 +131,14 @@ public class NotificationTimerTask extends TimerTask implements PlayerListener {
@Override @Override
public void onFinished() { public void onFinished() {
isPlaying = false; isPlaying = false;
new Thread(() -> {
try {
currentAyah = Ayah.getAyah(currentAyah.getNumber() + 1, currentAyah.getEdition());
} catch (IOException e) {
throw new RuntimeException(e);
}
}).start();
player = new AudioPlayer(currentAyah.getAudioUrl()).setListener(this);
player.play();
} }
} }