답변

1

음악 파일에 액세스하고 재생해야합니다. 네이티브 항목에 액세스하는 데 도움이되는 코도 바 플러그인이 있습니다. 프로젝트에 하나 또는 여러 개의 플러그인을 추가 한 후 github repos에 매우 유용한 문서와 예제가 있다는 것을 발견했습니다. npm 페이지에는 이들에 대한 링크가 있습니다. https://www.npmjs.com/package/cordova-plugin-file

  • 은 코르도바 - 플러그인 - iospicker : https://www.npmjs.com/package/cordova-plugin-iosaudiopicker
  • 은 코르도바 - 플러그인 - mediapicker :에 https://github.com/an-rahulpandey/cordova-plugin-mediapicker
  • 을 기반으로 액세스하는 파일의 경우

    +0

    로컬 네트워크에서 미디어 파일을 안전하게 제공 할 수있는 플러그인을 알고 있습니까? 컴퓨터의 음악 파일에 액세스하고 싶습니다. – arjun

    0

    모든 폴더와 파일 목록이 표시됩니다이 코드 :

    import { File } from "@ionic-native/file"; 
        import { Diagnostic } from "@ionic-native/diagnostic"; 
    
        constructor(
         ... 
         public file: File, 
         public diagnostic: Diagnostic 
         ){ 
    
    
        // ------------------------- 
        listFileSys(which){ 
    
        // <which> chooses the file system - see switch below 
        this.jcDebug += "\n" + "listFileSysSKOFLO(" + which + ")"; 
    
        let fileSysArray = []; 
        let basePath = ""; 
    
        let tag = "unknown"; 
    
        // ************** RECURSE ************* 
        let jcListDir = (thisDir)=>{ 
    
         tag = "jcListDir: [" + thisDir + "]"; 
    
         this.file.listDir(basePath, thisDir) 
         .then((data)=>{ 
         tag = "listDir:" + thisDir; 
         this.jcError += "\n" + tag + ":" + JSON.stringify(data); 
         for(let ii = 0; ii < data.length; ii += 1){ 
          this.jcError += "\n" + data[ii].name + (data[ii].isDirectory? " [D]" : " [F]"); 
    
          let currentPath = thisDir; 
          currentPath += (currentPath.length ? "/" : ""); 
          currentPath += data[ii].name; 
          this.jcError += "\n" + "currentPath:" + currentPath; 
    
          fileSysArray.push(currentPath); 
    
          if(data[ii].isDirectory && ok2recurse){ 
          jcListDir(currentPath);   // RECURSE !!! 
          } 
         } 
         }, (errData)=>{ 
         tag = "listDir"; 
         this.jcError += "\n" + tag + ":ERR:" + JSON.stringify(errData); 
         }); 
        }; 
        // ************** RECURSE ************* 
    
        // *********************** 
        let runListDir =()=>{ 
         this.jcDebug += "\n" + "basePath:" + basePath; 
    
         // !!! START listing from basePath !!! 
         jcListDir("."); 
        } 
    
        // *********************** 
        switch(which) 
        { 
         case 1: 
         this.diagnostic.getExternalSdCardDetails() 
         .then((data) => { 
          this.jcDebug += "\n" + "sd:" + JSON.stringify(data); 
          this.jcDebug += "\n" + "Number of cards: " + data.length; 
          for(let ii = 0; ii < data.length; ii += 1){ 
          let thisElem = data[ii]; 
          if(thisElem.type.toLowerCase() === "application" && thisElem.canWrite){ 
           basePath = thisElem.filePath; 
           break; 
          } 
          } 
          if(!basePath){ 
          this.jcDebug += "\n" + "no SD card found"; 
          return; 
          } 
          runListDir(); 
         }, (errData)=>{ 
          tag = "getExternalSdCardDetails"; 
          this.jcError += "\n" + tag + ":ERR:" + JSON.stringify(errData); 
         }); 
         break; 
         case 2: 
         basePath = this.file.externalDataDirectory; 
         this.jcError += "\n" + "externalDataDirectory:" + basePath; 
         runListDir(); 
         break; 
         case 3: 
         basePath = this.file.dataDirectory; 
         this.jcError += "\n" + "dataDirectory:"; 
         runListDir(); 
         break; 
         default: 
         alert("which???:" + which); 
         return; 
        } 
    
        // wait for all to comnplete, then show 
        // assume 1000 ms is adequate delay per promise 
        let lastFileSysLen = -1 
        let checkCount = 30; // max 30 * 1000 ms = 30 seconds 
    
        // ************** RECURSE ************* 
         let checkComplete =() => { 
         this.jcDebug += "\n" + "checkComplete " + checkCount + " [" + fileSysArray.length + "]"; 
         setTimeout(()=>{ 
    
         // fileSysArr length stable? 
         if(fileSysArray.length === lastFileSysLen){ 
          checkCount = 0; 
         } 
         lastFileSysLen = fileSysArray.length; 
    
         checkCount -= 1; 
         if(checkCount > 0){ 
          checkComplete(); // recurse 
         } else { 
    
          // STOP !!! and show FileSysArray 
          this.jcInfo += "\n" + "show FileSysArray"; 
          this.jcInfo += "\n" + "fileSysArray.length = " + " [" + fileSysArray.length + "]"; 
    
          fileSysArray.sort(); 
    
          for(let elem of fileSysArray){ 
          this.jcInfo += "\n" + elem; 
          } 
         } 
         }, 1000); 
        }; 
        // ************** RECURSE ************* 
        checkComplete(); 
        } 
    
    관련 문제