美化一下wordpress的默认媒体播放器推荐

两天 学习资料1 16.6K3字数 4590阅读15分18秒阅读模式
摘要默认媒体播放器实在是太丑了点急需美化一下。

由于现在各种音乐播放插件相继失联(hermit、hermit-X等),网易云QQ酷狗等各大平台没法再博客中插入播放了。就算是作为本地播放器,由于WordPress和PHP版本的不断更新,这些插件也是各种错误,真是让人感到头大。奈何自己一点基础都没,除了干瞪眼啥也做不了。
所以现在只能把需要插入歌曲的地方换成默认播放器了。但是,默认播放器实在是太丑了点。就只好对自带播放器美化一下了。

经过不断地换词搜索,终于找到了一篇对默认媒体播放器进行美化的文章,虽然看上去美化的也是十分简陋,但是奈何我也不不懂css,就将就着用吧,至少比默认的好看多了。

效果参照本文播放器:

单首歌曲:文章源自两天的博客-https://2days.org/84901.html

歌曲列表:文章源自两天的博客-https://2days.org/84901.html

图片4447-wordpress修改默认的媒体播放器文章源自两天的博客-https://2days.org/84901.html

文章来自腾讯云:https://cloud.tencent.com/developer/article/2121979文章源自两天的博客-https://2days.org/84901.html

添加样式文件

主题css目录下新建文件my-theme-player.css文章源自两天的博客-https://2days.org/84901.html

/* Media Element Player styles */

/* Player background */
.mytheme-mejs-container.mejs-container,
.mytheme-mejs-container .mejs-controls,
.mytheme-mejs-container .mejs-embed,
.mytheme-mejs-container .mejs-embed body {
    background-color: #efefef;
}

/* Playmejs-time-floater controls */
.mytheme-mejs-container .mejs-button > button {
    background-image: url(images/mejs-controls-dark.svg);
}

.mytheme-mejs-container .mejs-time {
    color: #888888;
}

/* Progress and audio bars */

/* Progress and audio bar background */
.mytheme-mejs-container .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-total,
.mytheme-mejs-container .mejs-controls .mejs-time-rail .mejs-time-total {
    background-color: #fff;
}

/* Track progress bar background (amount of track fully loaded)
  We prefer to style these with the main accent color of our theme */
.mytheme-mejs-container .mejs-controls .mejs-time-rail .mejs-time-loaded {
    background-color: rgba(219, 78, 136, 0.075);
}

/* Current track progress and active audio volume level bar */
.mytheme-mejs-container .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-current,
.mytheme-mejs-container .mejs-controls .mejs-time-rail .mejs-time-current {
    background: #db4e88;
}

/* Reduce height of the progress and audio bars */
.mytheme-mejs-container .mejs-time-buffering,
.mytheme-mejs-container .mejs-time-current,
.mytheme-mejs-container .mejs-time-float,
.mytheme-mejs-container .mejs-time-float-corner,
.mytheme-mejs-container .mejs-time-float-current,
.mytheme-mejs-container .mejs-time-hovered,
.mytheme-mejs-container .mejs-time-loaded,
.mytheme-mejs-container .mejs-time-marker,
.mytheme-mejs-container .mejs-time-total,
.mytheme-mejs-container .mejs-horizontal-volume-total,
.mytheme-mejs-container .mejs-time-handle-content {
    height: 3px;
}

.mytheme-mejs-container .mejs-time-handle-content {
    top: -6px;
}

.mytheme-mejs-container .mejs-time-total {
    margin-top: 8px;
}

.mytheme-mejs-container .mejs-horizontal-volume-total {
    top: 19px;
}

/* WordPress audio playlist styles */

.wp-playlist-light {
    box-shadow: 3px 3px 0 #e2e2e2;
}

/* Captions - Track titles / subtitles, time */
.wp-playlist-light .wp-playlist-caption,
.wp-playlist-light .wp-playlist-item-length {
    color: #787878;
}

/* Captions - Current track */
.wp-playlist-light .wp-playlist-current-item .wp-playlist-item-title {
    font-size: 16px;
}

.wp-playlist-light .wp-playlist-item-album {
    font-style: normal;
}

.wp-playlist-light .wp-playlist-item-artist {
    text-transform: none;
    opacity: .8;
}

/* Playlist items */
.wp-playlist-light .wp-playlist-item {
    padding: 10px 0;
    border-bottom-color: #efefef;
}

.wp-playlist-light .wp-playlist-item:last-child {
    padding-bottom: 0;
}

.wp-playlist-light .wp-playlist-playing {
    font-weight: normal;
    border-bottom-color: #db4e88;
}

.wp-playlist-light .wp-playlist-item-length {
    top: 10px;
}

/*调整优化*/
.mejs-time-float,.mejs-time-float-current,.mejs-time-float-corner{
    border:none ;
    color: #888888; /*设置文字颜色*/
}
.wp-audio-shortcode a,.wp-playlist a{
    border-bottom:none; /*去除主题的a标签全局下划线*/
}

添加svg播放图标
mejs-controls-dark.svg放置在主题css/images<c/ode>目录下css/images/mejs-controls-dark.svg文章源自两天的博客-https://2days.org/84901.html

下载:
https://d.pr/f/Y83MD
https://pan.baidu.com/s/14P4TOe1StJQfoRHgAmMrkg#提取码: 4pjf文章源自两天的博客-https://2days.org/84901.html

挂载脚本

functions.php适当位置添加css和js加载的钩子文章源自两天的博客-https://2days.org/84901.html

//加载之前新建的my-theme-player.css文件
//判断启用wp-mediaelement才会加载  避免多余的资源请求 
add_action( 'wp_footer', 'ci_theme_footer_scripts' );

function ci_theme_footer_scripts() {
    if ( wp_style_is( 'wp-mediaelement', 'enqueued' ) ) {
        wp_enqueue_style( 'my-theme-player', get_template_directory_uri() . '/css/my-theme-player.css', array(
            'wp-mediaelement',
        ), '1.0' );
    }
}

//给MediaElementJs播放器添加自定义样式mytheme-mejs-container  用于重写系统自带css
/**
 * Add an HTML class to MediaElement.js container elements to aid styling.
 *
 * Extends the core _wpmejsSettings object to add a new feature via the
 * MediaElement.js plugin API.
 */
add_action( 'wp_print_footer_scripts', 'mytheme_mejs_add_container_class' );

function mytheme_mejs_add_container_class() {
    if ( ! wp_script_is( 'mediaelement', 'done' ) ) {
        return;
    }
    ?>
    <script>
        (function() {
            var settings = window._wpmejsSettings || {};
            settings.features = settings.features || mejs.MepDefaults.features;
            settings.features.push( 'exampleclass' );
            MediaElementPlayer.prototype.buildexampleclass = function( player ) {
                player.container.addClass( 'mytheme-mejs-container' );
            };
        })();
    </script>
    <?php
}

参考:
https://www.cssigniter.com/css-style-guide-for-the-default-WordPress-media-player/
https://codex.WordPress.org/Playlist_Shortcode
文章源自两天的博客-https://2days.org/84901.html 文章源自两天的博客-https://2days.org/84901.html

本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!

weinxin
312379857
←QQ扫一扫添加QQ好友
版权声明:本站原创文章转载请注明文章出处及链接,谢谢合作!
广告也精彩
 最后更新:2023-11-25
  • MP3播放器
  • WordPress默认媒体播放器
  • hermit
  • hermit-X
  • 遇见台儿庄 遇见台儿庄

    看上去不错,再美化一下就好了 :idea:

    • 遇见台儿庄
      遇见台儿庄 4

      看上去不错,再美化一下就好了 :idea:

    匿名

    发表评论

    匿名网友
    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
    确定

    拖动滑块以完成验证