Skip to content

Commit 85e1553

Browse files
committed
AblePlayer should render an audio element if the loaded file is audio.
1 parent 0fc037e commit 85e1553

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/ableplayer.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ function ableplayer_shortcode( $atts, $content = null ) {
428428

429429
$source = '';
430430
$datasource = '';
431+
$element = 'video';
431432
if ( ! ( $all_atts['youtube-id'] || $all_atts['vimeo-id'] || $all_atts['media-id'] ) ) {
432433
// Shortcode must have one of YouTube, Vimeo, or a local source.
433434
return false;
@@ -438,9 +439,10 @@ function ableplayer_shortcode( $atts, $content = null ) {
438439
if ( ! $media_id ) {
439440
return false;
440441
} else {
441-
$type = get_post_mime_type( $all_atts['media-id'] );
442-
$type = ( $type === 'video/quicktime' ) ? 'video/mp4' : $type;
443-
$source = '<source type="' . esc_attr( $type ) . '" src="' . esc_url( $media_id ) . '"%datasrc%>' . PHP_EOL;
442+
$type = get_post_mime_type( $all_atts['media-id'] );
443+
$type = ( $type === 'video/quicktime' ) ? 'video/mp4' : $type;
444+
$element = ( wp_attachment_is( 'audio', $all_atts['media-id'] ) ) ? 'audio' : 'video';
445+
$source = '<source type="' . esc_attr( $type ) . '" src="' . esc_url( $media_id ) . '"%datasrc%>' . PHP_EOL;
444446
}
445447
}
446448
if ( $all_atts['media-desc-id'] ) {
@@ -491,7 +493,7 @@ function ableplayer_shortcode( $atts, $content = null ) {
491493
}
492494

493495
// build a video player.
494-
$o = '<video ';
496+
$o = "<$element ";
495497
$o .= ' id="' . esc_attr( $all_atts['id'] ) . '"';
496498
$o .= ' data-able-player';
497499
if ( ableplayer_is_true( $all_atts['autoplay'] ) ) {
@@ -574,7 +576,7 @@ function ableplayer_shortcode( $atts, $content = null ) {
574576
}
575577

576578
// end media tag.
577-
$o .= PHP_EOL . '</video>';
579+
$o .= PHP_EOL . "</$element>";
578580

579581
return $o;
580582
}

0 commit comments

Comments
 (0)