Perl Tips: mp3再生
2024/02/23 |
Perl Tips
[Prev]
|
効果音としてmp3ファイルを再生したい
素直にSendStringを使う
#!perl -w use Win32::MultiMedia::Mci (SendString); use IO::Handle; use strict; # ============================================================================== # メインclosure # ============================================================================== { STDOUT->IO::Handle::autoflush(1); # 画面表示都合によるSTDOUT出力バッファ無効化 # $m_op->{exec}オープン→再生 SendString('open "sound files\01 実行.mp3" alias exec'); # exec オープン SendString('open "sound files\02 パス.mp3" alias pass'); # pass オープン SendString('open "sound files\03 フェイル.mp3" alias fail'); # fail オープン SendString('play exec from 0 repeat'); # exec 非同期再生スタート # 10秒間再生維持 print "INF: async playing exec for 10[sec]: "; for (my $i=0; $i<10; $i++) { print $i; sleep(1); # 1秒wait } print "\n"; SendString('stop exec'); # exec 非同期再生ストップ # 0〜10範囲の乱数の値を見て、5より大きければpassとする if (rand(10) > 5) { print "INF: random result: pass\n"; SendString('play pass wait'); # pass同期再生 } else { print "INF: random result: fail\n"; SendString('play fail wait'); # fail同期再生 } } >mp3_playback_test_b.pl INF: async playing exec for 10[sec]: 0123456789 INF: random result: fail >mp3_playback_test_b.pl INF: async playing exec for 10[sec]: 0123456789 INF: random result: pass SendStringの使い方
|
2024-02-27: aliasによる不明動作回避を追記に伴いサンプルコードも変更 2024-02-23: 初版 Copyright(C) 2024 Altmo
本HPについて |
Perl Tips
[Prev]
|