Skip to content

Commit

Permalink
Merge pull request #114 from hyperaudio/108-explicitly-define-player
Browse files Browse the repository at this point in the history
108 explicitly define player
  • Loading branch information
maboa authored Sep 5, 2023
2 parents caf4019 + 0cf90ec commit 639ce56
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions wp-hyperaudio/hyperaudio-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ function hyperaudio_options_page()
<tr><td><code>font-family</code></td><td><code>Arial, Helvetica, sans-serif;</code></td><td>set the font family of the transcript</td></tr>
<tr><td><code>id</code></td><td><code>mytranscript</code></td><td>sets the id of the trancript for sharing purposes</td></tr>
<tr><td><code>show-active</code></td><td><code>true</code></td><td>highlights the word being played in a different colour. (<code>false</code> by default)</td></tr>
<tr><td><code>player</code></td><td><code>YouTube</code></td><td>Allows you to explicitly define type of player (SoundCloud, YouTube, Vimeo, Videojs, NativeAudio)</td></tr>
<tr><td><code>webmonetization</code></td><td><code>true</code></td><td>enables <a href="https://webmonetization.org/">Web Monetization</a> (<code>false</code> by default)</td></tr>
</table>
</p>
Expand Down
28 changes: 19 additions & 9 deletions wp-hyperaudio/hyperaudio.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Official Hyperaudio Plugin
* Plugin URI: https://hyper.audio
* Description: Hyperaudio Interactive Transcript Player
* Version: 1.0.12
* Version: 1.0.13
* Author: Mark Boas
* Author URI: http://hyper.audio
**/
Expand Down Expand Up @@ -34,6 +34,7 @@ function hyperaudio_shortcode_handler($atts, $transcript, $tag)
$trackLabel = "English";
$webmonetization = false;
$showActive = false;
$player = NULL;

if (isset($atts['src'])) $src = $atts['src'];
if (isset($atts['width'])) $width = $atts['width'];
Expand All @@ -52,6 +53,9 @@ function hyperaudio_shortcode_handler($atts, $transcript, $tag)
if (isset($atts['webmonetization'])) $webmonetization = $atts['webmonetization'];
if (isset($atts['show-active'])) $showActive = $atts['show-active'];

if (isset($atts['player'])) $player = $atts['player'];



$transcript = preg_replace( "/\r|\n/", "", $transcript);

Expand All @@ -64,6 +68,10 @@ function hyperaudio_shortcode_handler($atts, $transcript, $tag)
if (is_null($transcriptid)) {
$transcriptid = "hypertranscript".$id;
}

if (strtolower($player) == 'videojs') {
$o .='<link href="https://vjs.zencdn.net/8.5.2/video-js.css" rel="stylesheet" />';
}

$o .='<style>
Expand Down Expand Up @@ -163,17 +171,19 @@ function hyperaudio_shortcode_handler($atts, $transcript, $tag)

$o .='<div id="video-holder">';

if (strpos(strtolower($src), 'youtube.com') !== false || strpos(strtolower($src), 'youtu.be') !== false) {
if (strpos(strtolower($src), 'youtube.com') !== false || strpos(strtolower($src), 'youtu.be') !== false || strtolower($player) == 'youtube') {
if (isset($atts['media-height'])) {
$o .= '<div><iframe id="hyperplayer'. esc_attr( $id ) .'" class="hyperaudio-player" width="'. esc_attr( $width ) .'" height="'. esc_attr( $mediaHeight ).'" data-player-type="youtube" frameborder="no" allow="autoplay" src="'. esc_url( $src ) .'?enablejsapi=1"></iframe></div>';
$o .= '<div><iframe id="hyperplayer'. esc_attr( $id ) .'" class="hyperaudio-player" width="'. esc_attr( $width ) .'" height="'. esc_attr( $mediaHeight ).'" data-player="youtube" frameborder="no" allow="autoplay" src="'. esc_url( $src ) .'?enablejsapi=1"></iframe></div>';
} else {
$o .= '<div class="iframe-container"><iframe id="hyperplayer'. esc_attr( $id ).'" class="hyperaudio-player iframe-video" width="'. esc_attr( $width ) .'" data-player-type="youtube" frameborder="no" allow="autoplay" src="'. esc_url( $src ) .'?enablejsapi=1"></iframe></div>';
$o .= '<div class="iframe-container"><iframe id="hyperplayer'. esc_attr( $id ).'" class="hyperaudio-player iframe-video" width="'. esc_attr( $width ) .'" data-player="youtube" frameborder="no" allow="autoplay" src="'. esc_url( $src ) .'?enablejsapi=1"></iframe></div>';
}
} elseif (strpos(strtolower($src), 'vimeo.com') !== false) {
$o .= '<iframe id="hyperplayer'. esc_attr( $id ) .'" class="hyperaudio-player" data-player-type="vimeo" src="'. esc_url( $src ) .'" width="'. esc_attr( $width ) .'" height="'. esc_attr( $height ).'" frameborder="no" allowfullscreen allow="autoplay; encrypted-media"></iframe><script src="https://player.vimeo.com/api/player.js"></script>';
} elseif (strpos(strtolower($src), 'soundcloud.com') !== false) {
$o .= '<iframe id="hyperplayer'. esc_attr( $id ) .'" class="hyperaudio-player" data-player-type="soundcloud" scrolling="no" frameborder="no" allow="autoplay" src="'. esc_url( $src ) .'" style="width: '. esc_attr( $width ) .'"></iframe><script src="https://w.soundcloud.com/player/api.js"></script>';
} elseif (strpos(strtolower($src), '.mp3') !== false) {
} elseif (strpos(strtolower($src), 'vimeo.com') !== false || strtolower($player) == 'vimeo') {
$o .= '<iframe id="hyperplayer'. esc_attr( $id ) .'" class="hyperaudio-player" data-player="vimeo" src="'. esc_url( $src ) .'" width="'. esc_attr( $width ) .'" height="'. esc_attr( $height ).'" frameborder="no" allowfullscreen allow="autoplay; encrypted-media"></iframe><script src="https://player.vimeo.com/api/player.js"></script>';
} elseif (strpos(strtolower($src), 'soundcloud.com') !== false || strtolower($player) == 'soundcloud') {
$o .= '<iframe id="hyperplayer'. esc_attr( $id ) .'" class="hyperaudio-player" data-player="soundcloud" scrolling="no" frameborder="no" allow="autoplay" src="'. esc_url( $src ) .'" style="width: '. esc_attr( $width ) .'"></iframe><script src="https://w.soundcloud.com/player/api.js"></script>';
} elseif (strtolower($player) == 'videojs') {
$o .= '<video id="hyperplayer'. esc_attr( $id ) .'" class="hyperaudio-player video-js" data-player="videojs" data-setup="{}" style="position:relative" src="'. esc_url( $src ) .'" width="'. esc_attr( $width ) .'" height="'. esc_attr( $mediaHeight ) .'" controls><script src="https://vjs.zencdn.net/8.5.2/video.min.js"></script>';
} elseif (strpos(strtolower($src), '.mp3') !== false || strtolower($player) == 'nativeaudio') {
$o .= '<audio id="hyperplayer'. esc_attr( $id ) .'" class="hyperaudio-player" style="position:relative; width:'. esc_attr( $width ).'" src="'. esc_url( $src ) .'" controls></audio>';
} else {
$o .= '<video id="hyperplayer'. esc_attr( $id ) .'" class="hyperaudio-player" style="position:relative; width:'. esc_attr( $width ) .'" src="'. esc_url( $src ) .'" controls>';
Expand Down

0 comments on commit 639ce56

Please sign in to comment.