   'vendor/mediaelement-and-player'
   'jquery'
 ], (I18n, _, pubsub, mejs, $) ->
+
+  isIE9 = () -> $("body").hasClass("ie9")
+  isMobileDevice = () ->
+    agent = navigator.userAgent.toLowerCase()
+    agent.match(/ip(hone|od|ad)/i) or agent.match(/android/i)
+
+  browserSupportsVideoInAudioTag = () -> isMobileDevice()
 
   VIDEO_WIDTH = 550
   VIDEO_HEIGHT = 448

    {sourcesAndTracks, mediaType, height, width} = options
    tag_type = if mediaType is 'video' then 'video' else 'audio'

    sourceTypes = _.map sourcesAndTracks.sources, (source) -> $(source).attr('type')
    # A lot of our recorded audio is actually served up via video/mp4 or video/flv.
    # We need to trick the flash player into playing the video, but looking like
    # an audio player. (Not necessary on iOS/Android - they seem fine playing
    # an mp4 inside an audio tag.)
    if mediaType is 'audio' and sourceTypes[0].match(/^video\//) and !browserSupportsVideoInAudioTag()
      tag_type = 'video'
      options.mediaPlayerOptions.isVideo = false
      options.mediaPlayerOptions.videoHeight = 30

  $.extend mejs.MepDefaults,
    # prefer flash player, as it works more consistently
    # for now, but allow fallback to html5 (like on mobile)
    # Force IE9 to always use the plugin, because it has
    # problems with the canPlayType call.
    mode: if isIE9() then 'shim' else 'auto_plugin'
    success: (mediaElement, domObject) ->
      if(mediaElement.pluginType == 'flash')
        mediaElement.play()

  # track events in google analytics
  mejs.MepDefaults.features.push('googleanalytics')
