Code Monkey home page Code Monkey logo

cordova-media-scanner's Introduction

Cordova-Media-Scanner

Scan Files/Folders on Android Storage Device/Internal Device

Installation

The following are required to make the Media Scanner work properly in a Android platform. Follow the below instruction.

  • Install https://github.com/apache/cordova-plugin-file using npm cordova Refer to Android File System layout.
  • Install https://github.com/dpa99c/cordova-diagnostic-plugin to manage external/internal storage for Marshmallow 6.0. It will ask for permission .For < 6.0 it will automatically works.
  • add reference to media-scan.js in HTML5 Markup
  • Add reference to Angularjs . This is a Angularjs based cordova project
  • After reference has been added then kindly add cordova.file.media as a DI
var app = angular.module("myApp",["cordova.file.media"]);

Then in a Controller Inject Media

app.controller('globalCtrl', ['Media','$q',function (Media,$q) 
{

});

To call the Media Scanner.

    var url =   [
              "file:///storage/emulated/0/",
              "file:///mnt/sdcard/"
              ];
   
    fileType = ["mp3"];              

    function permissionRespfunction(resp)
    {
      if(resp=="GRANTED")
      {
         //load Loader
         var respArray =[];
         var file = Media.scan(url,fileType);

            file.then(function(resp)
            {
              
              
              if(resp.length!=0)
              {
                log("Before Removing Duplicates");
                log(resp);
                $scope.fileScan = Media.removeDuplicates(resp,"name");  //remove duplicaes based on Name
                log("After Removing Duplicates");
                log($scope.fileScan);
              }
              else
              {
                log("No Media Found...Please Scan Again");
                Media.permission();
              }

            });
          }
          else if(resp=="NOT_REQUESTED")
          {
  Media.permission(permissionRespfunction);  //Func Ends
          }
          else if(resp=="DENIED")
          {
  Media.permission(permissionRespfunction);  //Func Ends
          }
          else if(resp=="DENIED_ALWAYS")
          {
  Media.permission(permissionRespfunction);  //Func Ends
          }
          else if(resp=="DENIED_ALWAYS")
          {
  Media.permission(permissionRespfunction);  //Func Ends
          }

     }
    
  
  Media.permission(permissionRespfunction);  //Func Ends

Function Reference

  • Media.permission(cb) : this is a async func which check for permission if on marshmallow 6.0 and above. For <6.0 it will not ask for permission. cb is a callback function.

  • var file = Media.scan(url,fileType) : It is a promises which return all the files based on the file Type. Kindly refer to the above example. The fileType is a file extension as an array. for url please refer to Android File System.

  • Media.removeDuplicates : this function removes duplicates from the promise returned from Media.scan(url,fileType)

Suggestion

If you have any suggestion please feel free to ping me. Please file a bug report if you have some so that i can make it more future proof and fault tolerance. Work under dev for Angular 4/6

License

This is for the people. MIT.

cordova-media-scanner's People

Contributors

siddmegadeth avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

cordova-media-scanner's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.