Git Product home page Git Product logo

mediafacer's Introduction

1 ARUJ1yzwjpDp1aRX7oZrwQ

MediaFacer

An android library for the structured querying of the MediaStore to get media files in the simplest way possible taking in account both storage mediums on device

Download

To include MediaFacer in your project, your project should have minSdkVersion 19 and above.

You can download a jar from GitHub's releases page.

Or use Gradle: Add it in your your projects root build.gradle file

 allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}   

Add the dependency in the app level build.gradle file

dependencies {
	   implementation 'com.github.CodeBoy722:MediaFacer:1.0.3'
	}

Usage

The MediaFacer library already contains a set of classes for holding audio,video and image file data and each time a query is executed to get media files, the results always come in anyone of these classes.

videoContent :this class holds data for a specific video file.

audioContent : this class holds data for a specific audio file.

pictureContent : this class holds data for a specific image file.

audioAlbumContent : this class holds all audio files and data which are related to the same music album.

audioArtistContent : this class holds all audio files and data related to the same music Artist.

audioFolderContent : this class holds all audio files found in the same folder on the storage mediums.

pictureFolderContent : this class holds all image files found in the same folder on the storage mediums.

videoFolderContent : this class holds all video files found in the same folder on the storage mediums.

Getting audio files from the MediaStore

get all audio files

ArrayList<audioContent> audioContents;
audioContents = MediaFacer
                .withAudioContex(mContext)
                .getAllAudioContent(AudioGet.externalContentUri;

setting and playing audio in MediaPlayer object from audioContent class

Uri content = Uri.parse(audioContent.getAssetFileStringUri());
try {
            AssetFileDescriptor file = getActivity().getContentResolver().openAssetFileDescriptor(content, "r");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                player.setDataSource(file);
            }else {
                player.setDataSource(audioContent.getFilePath());
            }
            player.setLooping(false);
            player.prepare();
            player.start();
        } catch (Exception e) {
            e.printStackTrace();
}

get all audio files with similar albums

ArrayList<audioAlbumContent>  allAlbums;
    allAlbums = MediaFacer
                .withAudioContex(mContext)
                .getAllAlbums(AudioGet.externalContentUri);

get all audio files with similar artists

ArrayList<audioArtistContent> allArtists;
    
    ArrayList<String> ids = MediaFacer
                            .withAudioContex(mContext)
                            .getAllArtistIds(AudioGet.externalContentUri);
			    
    allArtists = MediaFacer
                 .withAudioContex(mContext)
                 .getAllArtists(ids,AudioGet.externalContentUri);

get all audio files in same folders

 ArrayList<audioFolderContent> buckets;
 buckets = MediaFacer
           .withAudioContex(mContext)
           .getAllAudioFolderContent();

Getting images from the MediaStore

get all images in the MediaStore.

ArrayList<pictureContent> allPhotos;

  allPhotos = MediaFacer
              .withPictureContex(mContext)
              .getAllPictureContents(PictureGet.externalContentUri);

loading and displaying images from pictureContent class, you can use Glide for this

ImageView picture = findViewById(R.id.picture);
Glide.with(mContext)
                    .load(Uri.parse(pictureContent.getAssertFileStringUri()))
                    .apply(new RequestOptions().centerCrop())
                    .into(picture);

get all folders containing pictures

ArrayList<pictureFolderContent> pictureFolders = new ArrayList<>();
      
      pictureFolders.addAll(MediaFacer.withPictureContex(mContext).getPictureFolders());
	
//now load images for the first pictureFolderContent object
	pictureFolders.get(0)
	.setPhotos(MediaFacer
	.withPictureContex(mContext)
	.getAllPictureContentByBucket_id(pictureFolders.get(0).getBucket_id());	

Getting Videos from the MediaStore

get all videos in the MediaStore.

ArrayList<videoContent> allVideos;
 allVideos = MediaFacer
             .withVideoContex(mContext)
             .getAllVideoContent(VideoGet.externalContentUri);

loading video into VideoView from videoContent class

VideoView playZone findViewById(R.id.vid_zone);
SeekBar seeker = findViewById(R.id.seeker);

 playZone.setVideoURI(Uri.parse(videoContent.getAssetFileStringUri()));
        playZone.requestFocus();
        seeker.setMax((int) videos.get(position).getVideoDuration());
        playZone.start();

get all folders containing videos

 ArrayList<videoFolderContent> videoFolders = new ArrayList<>();
      
     videoFolders.addAll(MediaFacer.withVideoContex(mContext).getVideoFolders(VideoGet.externalContentUri));
	
//now load videos for the first videoFolderContent object
	videoFolders.get(0)
	.setVideoFiles(MediaFacer.withVideoContex(mContext)
	.getAllVideoContentByBucket_id(videoFolders.get(0).getBucket_id());

mediafacer's People

Contributors

codeboy722 avatar

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.