【问题标题】:reading ID3 tag in NativeScript + Vue在 NativeScript + Vue 中读取 ID3 标签
【发布时间】:2019-10-24 06:50:11
【问题描述】:

我正在尝试在我的项目中读取 mp3 文件的 id3 标签,但似乎所有节点插件都依赖于 fs , 因为我收到了这个错误:TypeError: fs.exists is not a function

那么如何在 NativeScript 中读取 id3 标签?

【问题讨论】:

  • {N} !== Node,您必须以原生 iOS / Android 方式获取元数据。试试nativescript-media-metadata-retriever插件。
  • nativescript-media-metadata-retriever 好像需要 Angular 插件,有没有可以和 Vue 配合使用的插件,不需要 Angular?
  • 可能是你误会了,你真的尝试过这个插件吗?作者只是以 Angular 为例,因为他可能是 Angular 用户。该插件适用于所有风格/框架。
  • 我想在午餐时间,它需要 Angular 组件!我的坏事!

标签: vue.js nativescript fs id3


【解决方案1】:

{N} !== Node,您必须以原生 iOS / Android 方式获取元数据。使用nativescript-media-metadata-retriever插件。

tns plugin add nativescript-media-metadata-retriever

【讨论】:

  • 效果很好,非常感谢,你知道我怎样才能让它保持沉默吗?它记录了太多信息,我的意思是:[nativescript-media-metadata-retriever]: Data source has been set...' JS: '[nativescript-media-metadata-retriever]: All metadata extracted...' JS: '[nativescript-media-metadata-retriever]: Failed to generate bitmap...
  • 如何将coverAlbum 保存在SDCARD 中?我通过 mmr.getEmbeddedPicture().then( ( args ) => {...} ) 得到它,但我不知道如何将 args 保存为文件。
  • 我试图通过:let source = new imageSourceModule.ImageSource(); source.fromAsset( args ) .then( ( imageSource ) => {...}) 保存它,但它说:TypeError: asset.getImageAsync is not a function
  • getEmbeddedPicture() 的返回值不是ImageAsset,而是原生源。使用fromNativeSource 而不是fromAsset。一切都有据可查,请仔细阅读插件的 read me 和 {N} 文档。
  • 我刚刚找到了here的Module,没有提到fromNativeSource可以分享链接吗?
【解决方案2】:

你可以试试nativescript-nodeify,但我记得后来bundling有问题。

另外,我在 NativeScript 4 中使用过这个。我不知道这在 NS 6 中是否仍然有效。

【讨论】:

    【解决方案3】:

    为了像我这样的菜鸟,我分享我对这个模块的使用,他们会因为误解而浪费时间:))

    要求:

    import { MediaMetadataRetriever } from "nativescript-media-metadata-retriever";
    const imageSourceModule = require( "tns-core-modules/image-source" ); 
    const fs = require("tns-core-modules/file-system");
    

    和代码:

    // ------- init MediaMetadataRetriever         
    let mmr = new MediaMetadataRetriever();
    mmr.setDataSource( newValue );
    mmr.getEmbeddedPicture()
    .then( ( args ) => {
    
        // ------- show the albumArt on bgIMG
        var albumArt = this.$refs.bgIMG.nativeView; 
        var img = new imageSourceModule.ImageSource();
        // ------- setNativeSource is a **Methods** of imageSourceModule
        img.setNativeSource( args );
        albumArt.set( "src" , img );
        console.log("ImageSource set...");
    
        // ------- save the albumArt in root of SDCARD
        // ------- fromNativeSource is a **Function** of imageSourceModule
        let imageSource = imageSourceModule.fromNativeSource( args );
        console.log("Here");
        let fileName = "test.png";
        const root = android.os.Environment.getExternalStorageDirectory().getAbsolutePath().toString();
        let path = fs.path.join( root , fileName);
        let saved = imageSource.saveToFile(path, "png");
        if (saved) {
            console.log("Image saved successfully!");
        }
    
    } );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      • 2011-01-06
      • 1970-01-01
      • 1970-01-01
      • 2011-09-12
      • 2011-09-14
      相关资源
      最近更新 更多