GithubHelp home page GithubHelp logo

marekhalmo / flutter_cast_framework Goto Github PK

View Code? Open in Web Editor NEW

This project forked from angeloavv/flutter_cast_framework

0.0 0.0 0.0 673 KB

Google Cast SDK for flutter

Home Page: https://gianlucaparadise.github.io/flutter_cast_framework/api/

License: Apache License 2.0

Ruby 0.82% C 0.06% Objective-C 17.14% Java 20.18% Kotlin 11.56% Dart 36.36% Swift 13.19% Makefile 0.25% HTML 0.45%

flutter_cast_framework's Introduction

Flutter Cast Framework

Overview

Pub Version (including pre-releases)

Flutter Cast Framework is a POC of a flutter plugin that lets you use Chromecast API in a flutter app.

Useful links

Exposed APIs

Currently only the following APIs are integrated (both Android and iOS):

  • Cast State
  • Session state
  • Send custom message
  • Listen to received custom messages
  • Load RemoteMediaRequestData
  • Play, Pause, Stop media
  • Expanded controls
  • Mini Controller
  • Cast Button
  • Chromecast connection

Setup

Add Dependency

Run the following to add flutter_cast_framework to the dependencies:

flutter pub add flutter_cast_framework

Android Setup

1. Create CastOptionsProvider

Add the following class to 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

class CastOptionsProvider : OptionsProvider {
    override fun getCastOptions(context: Context): CastOptions {
        return CastOptions.Builder()
                .setReceiverApplicationId("4F8B3483") // Your receiver Application ID
                .build()
    }

    override fun getAdditionalSessionProviders(context: Context): List<SessionProvider>? {
        return null
    }
}

2. Load CastOptionsProvider

Add the following entry in the AndroidManifest.xml file under the <application> tag to reference the CastOptionsProvider class:

<application>
    <meta-data
        android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
        android:value="com.gianlucaparadise.flutter_cast_framework_example.CastOptionsProvider" />
</application>

3. Theme

Make sure that your application and your activity are using an AppCompat theme (as stated here).

iOS Setup

1. Minimum iOS version

Make sure you minimum iOS version is 10.0. Select Runner from left pane > General tab > Deployment Info > Target: set 10.0 or higher

2. Install iOS dependencies

When Xcode is closed, open a terminal at the root folder of your project and run:

cd ios && pod install

3. Open project in Xcode

To open your flutter project with Xcode, from root folder run open ios/Runner.xcworkspace

4. Chromecast SDK setup

Add the following lines to your AppDelegate.swift:

 import UIKit
 import Flutter
+import GoogleCast
 
 @UIApplicationMain
-@objc class AppDelegate: FlutterAppDelegate {
+@objc class AppDelegate: FlutterAppDelegate, GCKLoggerDelegate {
+  let kReceiverAppID = "4F8B3483" // Your receiver Application ID
+  let kDebugLoggingEnabled = true
+  
   override func application(
     _ application: UIApplication,
     didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
   ) -> Bool {
+    let criteria = GCKDiscoveryCriteria(applicationID: kReceiverAppID)
+    let options = GCKCastOptions(discoveryCriteria: criteria)
+    GCKCastContext.setSharedInstanceWith(options)
+
+    // Enable logger.
+    GCKLogger.sharedInstance().delegate = self
+    
     GeneratedPluginRegistrant.register(with: self)
     return super.application(application, didFinishLaunchingWithOptions: launchOptions)
   }
+  
+  // MARK: - GCKLoggerDelegate
+  
+  func logMessage(_ message: String,
+                  at level: GCKLoggerLevel,
+                  fromFunction function: String,
+                  location: String) {
+      if (kDebugLoggingEnabled) {
+          print(function + " - " + message)
+      }
+  }
 }

Tech notes

I used this project to test the capabilities of the following technologies:

  • Chromecast API (Sender - Android SDK)
  • Flutter
  • Flutter custom platform-specific code

Roadmap

Next features to be developed:

  • CC in Expanded Controls (iOS)
  • Expanded Controls cosmetics (ad in progress bar, full screen, progress bar handle)
  • Title in MiniController and ExpandedControls (blocked because of a pigeon issue, but solved with a workaround)
  • Handle queue
  • Handle progress seek
  • Understand if it is better to refactor using streams instead of listeners
  • Add tests
  • Various glitches and cosmetic fixes

flutter_cast_framework's People

Contributors

gianlucaparadise avatar angeloavv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.