3

I am developing a little music Player and I am trying to cast the current song to Chromecast. My app is based on Folders, so I manage mp3 or flac Files as songs.

I am following this Google Developers tutorial and I have written my Android Sender with the Media Chanel. If I do this, a song uploaded to dropbox plays succesfully on my TV.

    MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);

    MediaInfo mediaInfo = new MediaInfo.Builder(
    "https://dl.dropboxusercontent.com/u/56292608/MySong.mp3")
    .setContentType("audio/mp3")
    .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
    .setMetadata(mediaMetadata)
    .build()

mRemoteMediaPlayer.load(mApiClient, mediaInfo, true)

Is any way to cast or stream a File in order to set an URL?

I try with:

Uri.fromFile(myFile).toString()

but i can't send the file. Is any way to build the MediaInfo object reference from a local File path? If not, is any easy way to create a stream from a local path and send this stream to Chromecast?

In other case, it would be better transfering directly the multimedia sound from device with another approach?

Thanks for all

Juanjo
  • 298
  • 1
  • 15

1 Answers1

3

It is possible. Most ways that I have encountered involve:

  1. Create a barebones HTTP web server on the Android device.
  2. Direct Chromecast to stream from your phone using the web server.
  3. The web server then streams the file to the Chromecast.
Knossos
  • 15,802
  • 10
  • 54
  • 91
  • Hi Knossos. Is really needed all this work for that simply think?? Are any exaple or tutorial for try this step by step? – Juanjo Aug 17 '15 at 12:48
  • 1
    ie, if a user clicks on "next" button, I should upload te song to my own server, then connect this server to chromecast, and then serve the song?? its a little bit crazy this, is not? – Juanjo Aug 17 '15 at 12:55
  • 3
    It is all done locally. Basically, you start a server using something like NanoHTTP on your Android device. You have your video on your Android device on /sdcard/ or similar. You tell Chromecast to connect to http://your.android.internal.ip/name.of.video.mp4. Your Android devices HTTP server opens the video file and sends it to the Chromecast. For all the Chromecast knows, it is playing a file from an Internet server. However, it is simply your local Android device. – Knossos Aug 17 '15 at 13:19
  • @Knossos can you provide any demo source code? – Hanzala Oct 05 '22 at 08:25
  • No, but it has been 7 years. There must be some samples on the net. – Knossos Oct 05 '22 at 10:25