Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display image while playing an audio #6

Open
samarthagarwal opened this issue Oct 22, 2019 · 6 comments
Open

Display image while playing an audio #6

samarthagarwal opened this issue Oct 22, 2019 · 6 comments

Comments

@samarthagarwal
Copy link

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
Copy link
Author

Found the workaround.

@letiagoalves
Copy link

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

@samarthagarwal
Copy link
Author

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.

@subhash279
Copy link

You are a life saver :)

@subhash279
Copy link

@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?

@terrabythia
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants