Skip to content

Commit 4ea2932

Browse files
author
梶塚太智
authored
Merge pull request #16 from rensatopc/main
play sound
2 parents b1c12fa + f9e25ff commit 4ea2932

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ sys-info = "0.7.0"
1515
clap = "3.0"
1616
clearscreen = "2.0.1"
1717
clipboard = "0.5"
18+
rusty_audio = "1.4.1"

soundeg.mp3

69.2 KB
Binary file not shown.

src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clipboard::{ClipboardContext, ClipboardProvider};
33
use rand::seq::SliceRandom;
44
use regex::Regex;
55
use rodio::{OutputStream, Sink, Source};
6+
use rusty_audio::Audio;
67
use std::collections::HashMap;
78
use std::env;
89
use std::fs::{self, File};
@@ -1434,6 +1435,24 @@ impl Executor {
14341435
}
14351436
}
14361437

1438+
"play-file" => {
1439+
let path_as_str = self.pop_stack().get_string();
1440+
let soundfilepath = Path::new(&path_as_str);
1441+
1442+
let ressoundfile = File::open(soundfilepath);
1443+
if let Err(e) = ressoundfile {
1444+
self.log_print(format!("Error! {}\n", e));
1445+
self.stack.push(Type::Error("play-file".to_string()));
1446+
return;
1447+
}
1448+
1449+
let mut audiodevice = Audio::new();
1450+
audiodevice.add("sound", path_as_str);
1451+
audiodevice.play("sound");
1452+
1453+
audiodevice.wait();
1454+
}
1455+
14371456
// If it is not recognized as a command, use it as a string.
14381457
_ => self.stack.push(Type::String(command)),
14391458
}

0 commit comments

Comments
 (0)