2

我想将本地 mp3 文件从我的设备发送到 Chromecast。我已经运行了一个 Nanohttpd 版本,它运行良好,我可以在电视上播放我的歌曲而不会出现以下问题:

MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);

MediaInfo mediaInfo = new MediaInfo.Builder(
 "http://192.168.0.XX:8080")
.setContentType("audio/mp3")
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.setMetadata(mediaMetadata)
.build()

mRemoteMediaPlayer.load(mApiClient, mediaInfo, true) .....

...其中“ http://192.168.0.XX:8080 ”是我的服务器网址。

现在,我想为我的 mediaMetadata 添加一个封面,但是,为此,我还需要提供图片文件,因为这张图片作为 WebImage 发送到 Cromecast,如下所示:

mediaMetadata.addImage(new WebImage(Uri.parse("My Url in Nanohttpd ")));

可以直接从资源创建 WebImage 吗?

如果没有,有什么方法可以同时服务(歌曲和图片)?也许我可以在 http://192.168.0.XX:8080/song 提供歌曲,在 http://192.168.0.XX:8080/image 提供图片或类似的东西,但我不知道如何。 ..

这是我当前的 Nanohttpd 服务方法:

   @Override
    public Response serve(String uri, Method method,
                          Map<String, String> header,
                          Map<String, String> parameters,
                          Map<String, String> files) {

        String mediasend = "audio/mp3";
        FileInputStream fis = null;
        File song = new File(songLocalPath);
        Log.e("Creando imputStream", "Size: ");
            try {
                fis = new FileInputStream(song);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        Response.Status st = Response.Status.OK;
        return new NanoHTTPD.Response(st, mediasend, fis,song.length());
    } 

对此的每一种方法都会受到欢迎。

4

1 回答 1

2

好吧,最后我将 serve 方法更改为具有 2 个 URL 并区分它们:

@Override
public Response serve(String uri, Method method,
                      Map<String, String> header,
                      Map<String, String> parameters,
                      Map<String, String> files) {


 if (uri.contains("picture")){          
 //serve the picture 
      return new NanoHTTPD.Response(st, mediasend, fisPicture, f.length());

 }else if (uri.contains("song")){

 //serve the song
      return new NanoHTTPD.Response(st, mediasend, fisSong, f.length());
 }

在 Sender App 中,发送歌曲:

 MediaMetadata mediaMetadata = new       MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);

 MediaInfo mediaInfo = new MediaInfo.Builder(
 "http://192.168.0.XX:8080/song")
 .setContentType("audio/mp3")
 .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
 .setMetadata(mediaMetadata)
 .build()

 mRemoteMediaPlayer.load(mApiClient, mediaInfo, true)

对于专辑封面:

mediaMetadata.addImage(new WebImage(Uri.parse(http://192.168.0.XX:8080/picture));
于 2015-08-18T16:13:53.010 回答