flutter_chromecast_example
flutter_chromecast_example copied to clipboard
Display image while playing an audio
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.
Found the workaround.
@samarthagarwal Hi, I am having the same problem, how were you able to you get around this issue?
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.
You are a life saver :)
@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?
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.