flutter_chromecast_example icon indicating copy to clipboard operation
flutter_chromecast_example copied to clipboard

Display image while playing an audio

Open samarthagarwal opened this issue 5 years ago • 6 comments

Hi. I am trying to modify and use the solution you provided to play audio and it works. It also works to display images. But I need to display an image while the audio plays. I have tried this.

CastMedia(
            title: "Some title",
            contentId: AudioSongURL,
            images: [AudioCoverImageURL],
            contentType: "audio/mpeg",
          );

But this plays the audio with a black screen. The screen however shows a seekbar which shows the progress of the audio. Any help is highly appreciated.

samarthagarwal avatar Oct 22 '19 14:10 samarthagarwal

Found the workaround.

samarthagarwal avatar Oct 22 '19 18:10 samarthagarwal

@samarthagarwal Hi, I am having the same problem, how were you able to you get around this issue?

letiagoalves avatar Apr 26 '20 16:04 letiagoalves

I created a new class called CastMediaPlus. I read the official Google docs and implemented several new features. Here is an implementation of the class.

import 'package:dart_chromecast/casting/cast_media.dart';

class CastMediaPlus extends CastMedia {
  final String contentId;
  String title;
  String subtitle;
  String artist;
  String composer;
  bool autoPlay = true;
  double position;
  String contentType;
  List<String> images;

  CastMediaPlus({
    this.contentId,
    this.title,
    this.subtitle,
    this.artist,
    this.composer,
    this.autoPlay = true,
    this.position = 0.0,
    this.contentType = 'video/mp4',
    this.images,
  }) {
    if (null == images) {
      images = [];
    }
  }

  Map toChromeCastMap() {
    return {
      'type': 'LOAD',
      'autoPlay': autoPlay,
      'currentTime': position,
      'activeTracks': [],
      'media': {
        'contentId': contentId,
        'contentType': contentType,
        'images': images.map((image) {
          return {
            'url': image,
          };
        }).toList(),
        'title': title,
        'streamType': 'BUFFERED',
        'metadata': {
          'metadataType': 3,
          'title': title,
          'albumName': subtitle,
          'artist': artist,
          'composer': composer,
          'images': images.map((image) {
            return {
              'url': image,
            };
          }).toList(),
        }
      }
    };
  }
}

Now, you can use CastMediaPlus in place of CastMedia.

CastMediaPlus cmp = CastMediaPlus(
            title: "My title",
            subtitle: "My subtitle",
            artist: "Artist's name",
            composer: "Composer's name",
            contentId: "URL to the audio file",
            images: ["URL to the cover image"],
            contentType: 'audio/mp4',
);

Hope it helps. I wanted to release my own version of the plugin but I am kind of too busy to do it right now.

samarthagarwal avatar Apr 27 '20 10:04 samarthagarwal

You are a life saver :)

subhash279 avatar Oct 09 '20 07:10 subhash279

@samarthagarwal thanks for the details on showing images. Can you pls point me to the documentation you used. I am trying to change playback speed on the cast audio. Not sure where to start or if it's even possible. Do you have any idea about this?

subhash279 avatar Oct 09 '20 12:10 subhash279

Hope it helps. I wanted to release my own version of the plugin but I am kind of too busy to do it right now.

Would be way more helpful if you'd create a pull request for this repo instead of creating yet another version of this plugin. Since you already have everything working that shouldn't be that much work.

terrabythia avatar Oct 09 '20 14:10 terrabythia