research:rpi_radio
차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판이전 판다음 판 | 이전 판 | ||
research:rpi_radio [2013/07/28 09:00] – [제어 구문 작성 (PHP)] stop.php에서 잘못된 -u 옵션 수정. changwoo | research:rpi_radio [2014/10/09 21:24] (현재) – 바깥 편집 127.0.0.1 | ||
---|---|---|---|
줄 67: | 줄 67: | ||
</ | </ | ||
웹서버의 주소를 통해 음악이 재생되는지 확인해본다! | 웹서버의 주소를 통해 음악이 재생되는지 확인해본다! | ||
+ | |||
+ | ===== 개선안 ===== | ||
+ | 위 방법은 테스트이고, | ||
+ | |||
+ | 아래 스크립트에서 각 방송국(스테이션)은 하위 디렉토리 하나를 점유하고 있으며 각 하위 디렉토리에는 각 채널의 그림 파일과 pls 파일을 보유하고 있다. | ||
+ | |||
+ | <code php ipcheck.php> | ||
+ | <?php | ||
+ | function ipcheck() | ||
+ | { | ||
+ | $allow = array(" | ||
+ | |||
+ | foreach($allow as $ip) | ||
+ | if(eregi($ip, | ||
+ | return; | ||
+ | |||
+ | die(' | ||
+ | } | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | <code php index.php> | ||
+ | <?php | ||
+ | include(' | ||
+ | ipcheck(); | ||
+ | |||
+ | function get_channels($sitename) | ||
+ | { | ||
+ | $handle = opendir(" | ||
+ | $channels = array(); | ||
+ | while(false !== ($entry = readdir($handle))) | ||
+ | { | ||
+ | $path = pathinfo($entry); | ||
+ | $name = $path[' | ||
+ | $ext = $path[' | ||
+ | |||
+ | if($ext == ' | ||
+ | array_push($channels, | ||
+ | } | ||
+ | sort($channels); | ||
+ | return $channels; | ||
+ | } | ||
+ | |||
+ | function get_img($channel) | ||
+ | { | ||
+ | $exts = array(' | ||
+ | foreach($exts as $e) | ||
+ | { | ||
+ | $imgfile = $channel.$e; | ||
+ | if(file_exists($imgfile)) | ||
+ | return $imgfile; | ||
+ | } | ||
+ | |||
+ | return ""; | ||
+ | } | ||
+ | ?> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <meta http-equiv=" | ||
+ | <style type=" | ||
+ | .station {margin-right: | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <div class=" | ||
+ | < | ||
+ | <ul> | ||
+ | <?php | ||
+ | // print all .pls file in the current directory | ||
+ | $difm = get_channels(' | ||
+ | foreach($difm as $ch) | ||
+ | { | ||
+ | $url = urlencode(" | ||
+ | $img = get_img(" | ||
+ | echo "< | ||
+ | } | ||
+ | ?> | ||
+ | </ul> | ||
+ | </ | ||
+ | <div class=" | ||
+ | < | ||
+ | <ul> | ||
+ | <?php | ||
+ | $skyfm = get_channels(' | ||
+ | foreach($skyfm as $ch) | ||
+ | { | ||
+ | $url = urlencode(" | ||
+ | $img = get_img(" | ||
+ | echo "< | ||
+ | } | ||
+ | ?> | ||
+ | </ul> | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <code php control.php> | ||
+ | <?php | ||
+ | include(' | ||
+ | ipcheck(); | ||
+ | ?> | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | <?php | ||
+ | function play($channel) | ||
+ | { | ||
+ | $filename = str_replace(' | ||
+ | $cmd = "sudo -u radio mplayer -playlist $filename.pls 1>/ | ||
+ | exec($cmd); | ||
+ | echo "< | ||
+ | } | ||
+ | |||
+ | function stop() | ||
+ | { | ||
+ | exec(' | ||
+ | echo "< | ||
+ | } | ||
+ | |||
+ | if($_GET[" | ||
+ | { | ||
+ | $channel = $_GET[' | ||
+ | echo " | ||
+ | if(file_exists($channel." | ||
+ | { | ||
+ | stop(); | ||
+ | play($channel); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | echo " | ||
+ | } | ||
+ | } | ||
+ | else if($_GET[" | ||
+ | { | ||
+ | stop(); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | echo " | ||
+ | } | ||
+ | |||
+ | ?> | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | 이제는 각 스테이션 별 디렉토리 내부에 pls 파일만 채워 주면 알아서 웹페이지가 갱신되는 편리함이 추가되었다. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ===== 또다른 개선안 ===== | ||
+ | * < | ||
+ | * < | ||
+ | * 일지 중지 (pause) | ||
+ | * 볼륨 조정 (up, down, mute) | ||
+ | |||
research/rpi_radio.1375002030.txt.gz · 마지막으로 수정됨: 2014/10/09 21:23 (바깥 편집)