Last updated:
0 purchases
googlecast
googlecast #
A flutter plugin to connect to audio only chrome cast e.g Google Nest Mini e.t.c.
##Feature
- Load.
- Play.
- Pause.
- Stop.
copied to clipboard
##Platform
- Android.
- IOS (Not supported yet).
- Web (Not supported yet).
copied to clipboard
Getting Started #
Add the google cast sdk dependencies to your build.gradle file.
implementation 'com.google.android.gms:play-services-cast-framework:21.0.1'
implementation 'com.google.android.exoplayer:extension-cast:2.11.5'
copied to clipboard
Open your android folder and create a CastOptionsProvider class in your android project.
import android.content.Context;
import com.google.android.gms.cast.framework.CastOptions;
import com.google.android.gms.cast.framework.OptionsProvider;
import com.google.android.gms.cast.framework.SessionProvider;
import java.util.ArrayList;
import java.util.List;
public class CastOptionsProvider implements OptionsProvider {
private String app_id="CC1AD845";
public static final String CUSTOM_NAMESPACE = "urn:x-cast:radio_fm_am";
@Override
public CastOptions getCastOptions(Context context) {
List<String> supportedNamespaces = new ArrayList<>();
supportedNamespaces.add(CUSTOM_NAMESPACE);
CastOptions castOptions = new CastOptions.Builder()
.setReceiverApplicationId(app_id)
//.setSupportedNamespaces(supportedNamespaces)
.build();
return castOptions;
}
@Override
public List<SessionProvider> getAdditionalSessionProviders(Context context) {
return null;
}
}
copied to clipboard
Note: "CC1AD845" application id is the default Media Receiver Application id. If you want to get a custom application id you can checkout google cast sdk documentation to set it up.
Go to MainActivity in your project and import this.
import com.google.android.gms.cast.framework.CastContext;
import io.flutter.embedding.android.FlutterFragmentActivity;
copied to clipboard
Make your MainActivity extends FlutterFragmentActivity.
Add this to your MainActivity.
@Override
public void configureFlutterEngine(FlutterEngine flutterEngine){
CastContext.getSharedInstance(getApplicationContext());
}
copied to clipboard
Add the CastOptionsProvider to the metadata in your AndroidManifest.xml.
<meta-data
android:name=
"com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="com.radiofm.freeradio.CastOptionsProvider" />
copied to clipboard
Note: Change the value to the CastOptionsProvider location.
##Usage
import
'package:googlecast/CastController.dart';
copied to clipboard
Create Cast controller.
CastController castController=new CastController();
copied to clipboard
Set media item.
await castController.setMedia(url: music_url,title: title,subtitle: subtitle);
copied to clipboard
Note: Subtitle can be null
Load media on chromecast.
await castController.loadAudio();
copied to clipboard
Play media on chromecast.
await castController.play();
copied to clipboard
Pause media on chromecast.
await castController.pause();
copied to clipboard
Stop media on chromecast.
await castController.stop();
copied to clipboard
Add ChromeCast Button Widget.
GoogleCastButton(size: 35);
copied to clipboard
Listen to chromecast connection state.
GoogleChromeCast().connectionState.listen((event)async{
if(event!=null){
print("$event");
if(event){
}else{
}
}
});
copied to clipboard
Note: Return true if connected otherwise false.
Listen to chromcast state.
GoogleChromeCast().messageStream.listen((message){
if(message!=null){
print("$message");
if(message!=null){
if(message=="PLAYING"){
}else if(message=="IDLE"){
} else if(message=="BUFFERING"){
}else if(message=="LOADING"){
}else if(message=="PAUSED"){
}else if(message=="UNKNOWN"){
}else if(message=="ERROR"){
}
}
}
});
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.