@@ -60,8 +60,6 @@ class MediaBrowseTreeSnapshot(private val mBrowser : MediaBrowserCompat, private
6060 }
6161
6262 private fun takeBrowserSnapshotImpl (mItems : MutableList <MediaBrowserCompat .MediaItem >, executorService : ExecutorService ){
63- // Create output file
64-
6563 // Create output file
6664 val root = Environment .getExternalStorageDirectory()
6765 val dirsPath = root.absolutePath + " /Temp/"
@@ -84,7 +82,7 @@ class MediaBrowseTreeSnapshot(private val mBrowser : MediaBrowserCompat, private
8482 } catch (e: InterruptedException ) {
8583 e.printStackTrace()
8684 }
87- writeMediaItemToFile (item, pw, 1 ,
85+ visitMediaItemNode (item, pw, 1 ,
8886 executorService)
8987 writeCompleted.release()
9088 }
@@ -103,24 +101,13 @@ class MediaBrowseTreeSnapshot(private val mBrowser : MediaBrowserCompat, private
103101 }
104102 }
105103
106- private fun writeMediaItemToFile (mediaItem : MediaBrowserCompat .MediaItem ? , printWriter : PrintWriter , depth : Int ,
107- executorService : ExecutorService ) {
108- if (mediaItem != null ) {
109- val descriptionCompat = mediaItem.description
110104
111- // Tab the media item to the respective depth
112- val tabStr = String (CharArray (depth)).replace(" \u0000 " ,
113- " \t " )
114- val titleStr = if (descriptionCompat.title != null ) descriptionCompat.title.toString() else " NAN"
115- val subTitleStr = if (descriptionCompat.subtitle != null ) descriptionCompat.subtitle.toString() else " NAN"
116- val mIDStr = if (descriptionCompat.mediaId != null ) descriptionCompat.mediaId else " NAN"
117- val uriStr = if (descriptionCompat.mediaUri != null ) descriptionCompat.mediaUri.toString() else " NAN"
118- val desStr = if (descriptionCompat.description != null ) descriptionCompat.description.toString() else " NAN"
119- val infoStr = String .format(
120- " %sTitle:%s,Subtitle:%s,MediaId:%s,URI:%s,Description:%s" ,
121- tabStr, titleStr, subTitleStr, mIDStr, uriStr, desStr)
122- printWriter.println (infoStr)
105+ private fun visitMediaItemNode (mediaItem : MediaBrowserCompat .MediaItem ? , printWriter : PrintWriter , depth : Int ,
106+ executorService : ExecutorService ) {
107+ if (mediaItem != null ) {
108+ printMediaItemDescription(printWriter, mediaItem, depth)
123109 val mid = if (mediaItem.mediaId != null ) mediaItem.mediaId!! else " "
110+
124111 // If a media item is not a leaf continue DFS on it
125112 if (mediaItem.isBrowsable && mid != " " ) {
126113 val loaded = Semaphore (1 )
@@ -152,13 +139,29 @@ class MediaBrowseTreeSnapshot(private val mBrowser : MediaBrowserCompat, private
152139
153140 // Run DFS on all of the nodes children
154141 for (mediaItemChild in mChildren) {
155- writeMediaItemToFile (mediaItemChild, printWriter, depth + 1 ,
142+ visitMediaItemNode (mediaItemChild, printWriter, depth + 1 ,
156143 executorService)
157144 }
158145 }
159146 }
160147 }
161148
149+ private fun printMediaItemDescription (printWriter : PrintWriter , mediaItem : MediaBrowserCompat .MediaItem , depth : Int ){
150+ val descriptionCompat = mediaItem.description
151+ // Tab the media item to the respective depth
152+ val tabStr = String (CharArray (depth)).replace(" \u0000 " ,
153+ " \t " )
154+ val titleStr = if (descriptionCompat.title != null ) descriptionCompat.title.toString() else " NAN"
155+ val subTitleStr = if (descriptionCompat.subtitle != null ) descriptionCompat.subtitle.toString() else " NAN"
156+ val mIDStr = if (descriptionCompat.mediaId != null ) descriptionCompat.mediaId else " NAN"
157+ val uriStr = if (descriptionCompat.mediaUri != null ) descriptionCompat.mediaUri.toString() else " NAN"
158+ val desStr = if (descriptionCompat.description != null ) descriptionCompat.description.toString() else " NAN"
159+ val infoStr = String .format(
160+ " %sTitle:%s,Subtitle:%s,MediaId:%s,URI:%s,Description:%s" ,
161+ tabStr, titleStr, subTitleStr, mIDStr, uriStr, desStr)
162+ printWriter.println (infoStr)
163+ }
164+
162165 private fun notifyUser (textToNotify : String ) {
163166 Handler (Looper .getMainLooper()).post {
164167 val toast = Toast .makeText(
0 commit comments