Blogger Information
Blog 43
fans 0
comment 3
visits 27031
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用jsmediatags获取mp3音乐文件封面
Time
Original
982 people have browsed it

1.下载文件地址https://github.com/aadsm/jsmediatags

2.引用dist下面的jsmediatags.min.js文件

<script src="jsmediatags.min.js"></script>

3.body测试代码

  1. <body>
  2. <form>
  3. <input id="$inputTypeFile" type="file" name="audio" accept="audio/*">
  4. <input type="submit" name="submit" value="add music"/>
  5. </form>
  6. <img src="" alt="" width="500px" height="500px">
  7. </body>

4.js代码

  1. <script>
  2. // From File
  3. $inputTypeFile.addEventListener("change", function(event) {
  4. var file = event.target.files[0];
  5. jsmediatags.read(file, {
  6. onSuccess: function(tag) {
  7. console.log(tag);
  8. var picture = tag.tags.picture; // create reference to track art
  9. var base64String = "";
  10. for (var i = 0; i < picture.data.length; i++) {
  11. base64String += String.fromCharCode(picture.data[i]);
  12. }
  13. var imageUri = "data:" + picture.format + ";base64," + window.btoa(base64String);
  14. document.querySelector('img').src=imageUri;
  15. // use ajax to upload tag info, or create some new form elements
  16. },
  17. onError: function(error) {
  18. console.log(error);
  19. }
  20. });
  21. }, false);
  22. </script>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post