時刻に合わせて自動的に BGM を再生

概要

時刻に合わせて自動的に BGM を切り替えるシステムを構築した。

最初は Raspberry Pi + Volumio2(アラーム機能) で運用していたが、BGM が止まったり、指定時刻になっても切り替わらないなど、不安定すぎて使い物にならず。

Raspberry Pi + Raspbian + MPD + cron の構成に切り替えることにした。現在5日ほど運用しているが全く問題無く安定稼働中。

具体的な運用として現在は、朝(6:00~)、昼(12:00~)、晩(20:00~)で 自動的に BGM を変更している。

MPD のインストール

下記の記事を参照。

MPD のインストールと設定
Volumio2 の安定性がイマイチなので、Raspbian(jessie) + MPD へ移行することにした。 インストール $ sudo apt-get install mpc mpd MPD を制御するコマンドラインツール mp...

BGM の準備

/var/lib/mpd/music ディレクトリに BGM に使用する音楽ファイルをコピーしておく。ディレクトリを作ってその下に置いても OK(デフォルトでは3層まで)

一応パーミッションを変更しておく。

$ sudo chmod -R 777 /var/lib/mpd/music

music ディレクトを samba で共有しておくと後の管理が楽。

Samba で特定のディレクトリを共有する
インストール $ sudo apt-get install samba samba-common-bin   設定 /etc/samba/smb.conf ファイルに以下の内容を追加する。 comment = <コメ...

プレイリストの準備

登録

morning,noon,night という名前のプレイリストを用意する。

プレイリストは標準的な m3u 形式で、/var/lib/mpd/playlist ディレクトリに配置する。

m3u 形式はプレーンテキストで、ファイル名を羅列したもの。

■ morning.m3u の例。

高原の朝/01 春の訪れ (清里).mp3
高原の朝/02 雨上がりの朝 (清里・美し森).mp3
高原の朝/03 安らぎの森 (富士山麓).mp3
高原の朝/04 高原のせせらぎ (軽井沢).mp3
高原の朝/05 新緑の季節 (富士山麓).mp3

確認

登録したプレイリストの一覧を表示。

$ mpc lsplaylists

プレイリストの内容を表示。

$ mpc playlist <プレイリスト名>

mpc クライアントの利用

GMPC 等のプレイリスト作成機能を持った mpc クライアントを使用すると GUI で操作できて便利。

GMPC は linux 以外に Windows 版もある。

Placeholder – Antagonist

再生設定

キューを繰り返し再生(エンドレス)するように設定。

$ mpc repeat on

cron の設定

cron で指定時刻に mpc コマンドを実行し MPD をコントロールする。

$ crontab -e

■ 設定例

# m h dom mon dow command
00 06 * * * mpc clear; mpc load morning; mpc play
00 12 * * * mpc clear; mpc load noon; mpc play
00 20 * * * mpc clear; mpc load night; mpc play

mpc clear でカレントプレイリスト(キュー)をクリアし、mpc load でプレイリストをキューに登録、mpc play で再生する。

参考 : mpc コマンド

Commands:
  mpc                                                   Display status
  mpc add <uri>                                         Add a song to the current playlist
  mpc crop                                              Remove all but the currently playing song
  mpc current                                           Show the currently playing song
  mpc del <position>                                    Remove a song from the current playlist
  mpc play [<position>]                                 Start playing at  (default: 1)
  mpc next                                              Play the next song in the current playlist
  mpc prev                                              Play the previous song in the current playlist
  mpc pause                                             Pauses the currently playing song
  mpc toggle                                            Toggles Play/Pause, plays if stopped
  mpc cdprev                                            Compact disk player-like previous command
  mpc stop                                              Stop the currently playing playlists
  mpc seek [+-][HH:MM:SS]| <0-100>%                     Seeks to the specified position
  mpc clear                                             Clear the current playlist
  mpc outputs                                           Show the current outputs
  mpc enable [only] <output # or name> [...]            Enable output(s)
  mpc disable [only] <output # or name> [...]           Disable output(s)
  mpc toggleoutput <output # or name> [...]             Toggle output(s)
  mpc shuffle                                           Shuffle the current playlist
  mpc move <from> <to>                                  Move song in playlist
  mpc playlist [<playlist>]                             Print 
  mpc listall [<file>]                                  List all songs in the music dir
  mpc ls [<directory>]                                  List the contents of 
  mpc lsplaylists                                       List currently available playlists
  mpc load <file>                                       Load  as a playlist
  mpc insert <uri>                                      Insert a song to the current playlist after the current track
  mpc save <file>                                       Save a playlist as 
  mpc rm <file>                                         Remove a playlist
  mpc volume [+-]<num>                                  Set volume to  or adjusts by [+-]
  mpc repeat <on|off>                                   Toggle repeat mode, or specify state
  mpc random <on|off>                                   Toggle random mode, or specify state
  mpc single <on|off>                                   Toggle single mode, or specify state
  mpc consume <on|off>                                  Toggle consume mode, or specify state
  mpc search <type> <query>                             Search for a song
  mpc find <type> <query>                               Find a song (exact match)
  mpc findadd <type> <query>                            Find songs and add them to the current playlist
  mpc list <type> [<type> <query>]                      Show all tags of <type>
  mpc crossfade [<seconds>]                             Set and display crossfade settings
  mpc clearerror                                        Clear the current error
  mpc mixrampdb [<dB>]                                  Set and display mixrampdb settings
  mpc mixrampdelay [<seconds>]                          Set and display mixrampdelay settings
  mpc update [<path>]                                   Scan music directory for updates
  mpc sticker <uri> <get|set|list|delete|find> [args..] Sticker management
  mpc stats                                             Display statistics about MPD
  mpc version                                           Report version of MPD
  mpc idle [events]                                     Idle until an event occurs
  mpc idleloop [events]                                 Continuously idle until an event occurs
  mpc replaygain [off|track|album]                      Set or display the replay gain mode
  mpc channels                                          List the channels that other clients have subscribed to.
  mpc sendmessage <channel> <message>                   Send a message to the specified channel.
  mpc waitmessage <channel>                             Wait for at least one message on the specified channel.
  mpc subscribe <channel>                               Subscribe to the specified channel and continuously receive messages.

コメント

タイトルとURLをコピーしました