public MediaItem createMediaItem ( String parentId , String mediaId , String title , int flag ) { final MediaMetadataCompat metadataCompat = new MediaMetadataCompat . Builder ( ) . putString ( MediaMetadataCompat . METADATA_KEY_MEDIA_ID , mediaId ) . putString ( MediaMetadataCompat . METADATA_KEY_TITLE , title ) . putString ( MediaMetadataCompat . METADATA_KEY_MEDIA_URI , Uri . parse ( mediaId ) . toString ( ) ) . build ( ) ; final MediaItem mediaItem = new MediaItem ( metadataCompat . getDescription ( ) , flag ) ; mediaItems . put ( mediaId , mediaItem ) ; // If this MediaItem is the child of a MediaItem that has already been created. This applies to // all MediaItems except the root. if ( parentId != null ) { final MediaItem parentItem = mediaItems . get ( parentId ) ; List < MediaItem > children = mediaItemChildren . get ( parentItem ) ; if ( children == null ) { children = new ArrayList <> ( ) ; mediaItemChildren . put ( parentItem , children ) ; } children . add ( mediaItem ) ; } return mediaItem ; }
Creates a MediaItem and returns it .