Skip to content

Commit

Permalink
cross browser audio play support
Browse files Browse the repository at this point in the history
  • Loading branch information
DracoLi committed Apr 2, 2013
1 parent 6fa4810 commit 10392f8
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -3,6 +3,11 @@ Triggio

Web app that connects events send from trusted sources to sounds that are played.

Meteorite is used instead of meteor (https://github.com/oortcloud/meteorite)


## Audio files
Please provide audio clips in mp3 format. Since Triggio uses [audio.js](http://kolber.github.com/audiojs/) it support most browser with flash used as fallback

### Useful Commands

Expand Down
18 changes: 15 additions & 3 deletions client/triggio.coffee
Expand Up @@ -2,6 +2,7 @@ Events = new Meteor.Collection "events"

if Meteor.isClient

# For testing
window.play_sound ||= play_sound

Meteor.startup ->
Expand Down Expand Up @@ -38,6 +39,17 @@ if Meteor.isClient


play_sound = (sound_id) ->
player = $('#clip_player').attr
'src': "/clips/#{sound_id}.mp3"
player[0].play()
# Remove any existing audio players
$('#clip_player').remove()
$('.audiojs').remove()

# Create a new audio player that autoplays
# This is done so audiojs can do its flash initialization if browser does not support mp3
audio = $('<audio>').attr
id: 'clip_player'
autoplay: true
preload: 'auto'
hidden: 'hidden'
src: "/clips/#{sound_id}.mp3"
$('body').append audio
audiojs.createAll()
24 changes: 24 additions & 0 deletions public/audiojs/audio.min.js

Large diffs are not rendered by default.

Binary file added public/audiojs/audiojs.swf
Binary file not shown.
Binary file added public/audiojs/player-graphics.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/clips/.DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions triggio.html
@@ -1,15 +1,15 @@
<head>
<title>Triggio | The Event Player by Loose Button Engineering</title>

<script src="/audiojs/audio.min.js"></script>
</head>

<body>
<div class="trigger-header">
<h1>Triggio</h1>
<h4>By Loose Button Engineering</h4>
</div>
{{> events}}

<audio id="clip_player" autoplay="autoplay" preload="auto" hidden="hidden"></audio>
{{> events}}
</body>

<template name="events">
Expand Down
2 changes: 2 additions & 0 deletions triggio.less
Expand Up @@ -8,6 +8,8 @@ html {

}

.audiojs { display: none; }

.trigger-header {
margin-top: 50px;
text-align: center;
Expand Down

0 comments on commit 10392f8

Please sign in to comment.