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

两天
两天
管理员
739
文章
0
粉丝
学习资料1 22,2643字数 778阅读2分35秒阅读模式
摘要默认媒体播放器实在是太丑了点急需美化一下。

由于现在各种音乐播放插件相继失联(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

  1. /* Media Element Player styles */
  2.  
  3. /* Player background */
  4. .mytheme-mejs-container.mejs-container,
  5. .mytheme-mejs-container .mejs-controls,
  6. .mytheme-mejs-container .mejs-embed,
  7. .mytheme-mejs-container .mejs-embed body {
  8. background-color: #efefef;
  9. }
  10.  
  11. /* Playmejs-time-floater controls */
  12. .mytheme-mejs-container .mejs-button > button {
  13. background-image: url(images/mejs-controls-dark.svg);
  14. }
  15.  
  16. .mytheme-mejs-container .mejs-time {
  17. color: #888888;
  18. }
  19.  
  20. /* Progress and audio bars */
  21.  
  22. /* Progress and audio bar background */
  23. .mytheme-mejs-container .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-total,
  24. .mytheme-mejs-container .mejs-controls .mejs-time-rail .mejs-time-total {
  25. background-color: #fff;
  26. }
  27.  
  28. /* Track progress bar background (amount of track fully loaded)
  29. We prefer to style these with the main accent color of our theme */
  30. .mytheme-mejs-container .mejs-controls .mejs-time-rail .mejs-time-loaded {
  31. background-color: rgba(219, 78, 136, 0.075);
  32. }
  33.  
  34. /* Current track progress and active audio volume level bar */
  35. .mytheme-mejs-container .mejs-controls .mejs-horizontal-volume-slider .mejs-horizontal-volume-current,
  36. .mytheme-mejs-container .mejs-controls .mejs-time-rail .mejs-time-current {
  37. background: #db4e88;
  38. }
  39.  
  40. /* Reduce height of the progress and audio bars */
  41. .mytheme-mejs-container .mejs-time-buffering,
  42. .mytheme-mejs-container .mejs-time-current,
  43. .mytheme-mejs-container .mejs-time-float,
  44. .mytheme-mejs-container .mejs-time-float-corner,
  45. .mytheme-mejs-container .mejs-time-float-current,
  46. .mytheme-mejs-container .mejs-time-hovered,
  47. .mytheme-mejs-container .mejs-time-loaded,
  48. .mytheme-mejs-container .mejs-time-marker,
  49. .mytheme-mejs-container .mejs-time-total,
  50. .mytheme-mejs-container .mejs-horizontal-volume-total,
  51. .mytheme-mejs-container .mejs-time-handle-content {
  52. height: 3px;
  53. }
  54.  
  55. .mytheme-mejs-container .mejs-time-handle-content {
  56. top: -6px;
  57. }
  58.  
  59. .mytheme-mejs-container .mejs-time-total {
  60. margin-top: 8px;
  61. }
  62.  
  63. .mytheme-mejs-container .mejs-horizontal-volume-total {
  64. top: 19px;
  65. }
  66.  
  67. /* WordPress audio playlist styles */
  68.  
  69. .wp-playlist-light {
  70. box-shadow: 3px 3px 0 #e2e2e2;
  71. }
  72.  
  73. /* Captions - Track titles / subtitles, time */
  74. .wp-playlist-light .wp-playlist-caption,
  75. .wp-playlist-light .wp-playlist-item-length {
  76. color: #787878;
  77. }
  78.  
  79. /* Captions - Current track */
  80. .wp-playlist-light .wp-playlist-current-item .wp-playlist-item-title {
  81. font-size: 16px;
  82. }
  83.  
  84. .wp-playlist-light .wp-playlist-item-album {
  85. font-style: normal;
  86. }
  87.  
  88. .wp-playlist-light .wp-playlist-item-artist {
  89. text-transform: none;
  90. opacity: .8;
  91. }
  92.  
  93. /* Playlist items */
  94. .wp-playlist-light .wp-playlist-item {
  95. padding: 10px 0;
  96. border-bottom-color: #efefef;
  97. }
  98.  
  99. .wp-playlist-light .wp-playlist-item:last-child {
  100. padding-bottom: 0;
  101. }
  102.  
  103. .wp-playlist-light .wp-playlist-playing {
  104. font-weight: normal;
  105. border-bottom-color: #db4e88;
  106. }
  107.  
  108. .wp-playlist-light .wp-playlist-item-length {
  109. top: 10px;
  110. }
  111.  
  112. /*调整优化*/
  113. .mejs-time-float,.mejs-time-float-current,.mejs-time-float-corner{
  114. border:none ;
  115. color: #888888; /*设置文字颜色*/
  116. }
  117. .wp-audio-shortcode a,.wp-playlist a{
  118. border-bottom:none; /*去除主题的a标签全局下划线*/
  119. }

添加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

  1. //加载之前新建的my-theme-player.css文件
  2. //判断启用wp-mediaelement才会加载 避免多余的资源请求
  3. add_action( 'wp_footer', 'ci_theme_footer_scripts' );
  4.  
  5. function ci_theme_footer_scripts() {
  6. if ( wp_style_is( 'wp-mediaelement', 'enqueued' ) ) {
  7. wp_enqueue_style( 'my-theme-player', get_template_directory_uri() . '/css/my-theme-player.css', array(
  8. 'wp-mediaelement',
  9. ), '1.0' );
  10. }
  11. }
  12.  
  13. //给MediaElementJs播放器添加自定义样式mytheme-mejs-container 用于重写系统自带css
  14. /**
  15. * Add an HTML class to MediaElement.js container elements to aid styling.
  16. *
  17. * Extends the core _wpmejsSettings object to add a new feature via the
  18. * MediaElement.js plugin API.
  19. */
  20. add_action( 'wp_print_footer_scripts', 'mytheme_mejs_add_container_class' );
  21.  
  22. function mytheme_mejs_add_container_class() {
  23. if ( ! wp_script_is( 'mediaelement', 'done' ) ) {
  24. return;
  25. }
  26. ?>
  27. <script>
  28. (function() {
  29. var settings = window._wpmejsSettings || {};
  30. settings.features = settings.features || mejs.MepDefaults.features;
  31. settings.features.push( 'exampleclass' );
  32. MediaElementPlayer.prototype.buildexampleclass = function( player ) {
  33. player.container.addClass( 'mytheme-mejs-container' );
  34. };
  35. })();
  36. </script>
  37. <?php
  38. }

参考:
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:
    确定

    拖动滑块以完成验证
    加载失败