ios - 我的代码是否未正确实现 google chromecast 按钮和流媒体功能?

标签 ios swift chromecast

我已经实现了 google chromecast 并以编程方式添加了按钮,但设备未显示按钮和流式传输能力。难道是我的代码写错了?

我已经尝试过这个指南 https://dev.to/lawgimenez/implement-chromecast-on-ios-using-swift-4dd4我的按钮没有显示我。

import UIKit
import AVKit
import QuickLook
import GoogleMobileAds
import GoogleCast

class MediaViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIDocumentInteractionControllerDelegate, QLPreviewControllerDelegate, QLPreviewControllerDataSource,     GADInterstitialDelegate, GCKSessionManagerListener, GCKRequestDelegate {

@IBOutlet weak var bannerView: DFPBannerView!
@IBOutlet weak var mediaTableView: UITableView!
private var castButton: GCKUICastButton!

var interstitial: GADInterstitial!


override func viewDidLoad() {
    super.viewDidLoad()

    castButton = GCKUICastButton(frame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(24), height: CGFloat(24)))
    // Overwrite the UIAppearance theme in the AppDelegate.
    castButton.tintColor = UIColor.white
    navigationItem.rightBarButtonItem = UIBarButtonItem(customView: castButton)
}

这是我的 Appdelegate.swift

import UIKit
import CoreData
import AVFoundation
import GoogleCast

let themeColor = UIColor(red: 0.01, green: 0.41, blue: 0.22, alpha: 1.0)

let kPrefPreloadTime = "preload_time_sec"
let kPrefEnableAnalyticsLogging = "enable_analytics_logging"
let kPrefAppVersion = "app_version"
let kPrefSDKVersion = "sdk_version"
let kPrefEnableMediaNotifications = "enable_media_notifications"

let appDelegate = (UIApplication.shared.delegate as? AppDelegate)

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GCKLoggerDelegate {

let kReceiverAppID = "6D744F12"
fileprivate var enableSDKLogging = true
fileprivate var mediaNotificationsEnabled = false
fileprivate var firstUserDefaultsSync = false
fileprivate var useCastContainerViewController = false
let kDebugLoggingEnabled = true

var window: UIWindow?
var isCastControlBarsEnabled: Bool!

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {


    // Override point for customization after application launch.
    let criteria = GCKDiscoveryCriteria(applicationID: kReceiverAppID)
    let options = GCKCastOptions(discoveryCriteria: criteria)
    options.physicalVolumeButtonsWillControlDeviceVolume = true
    GCKCastContext.setSharedInstanceWith(options)

    // Enable logger.
    let logFilter = GCKLoggerFilter()
    logFilter.minimumLevel = .verbose
    GCKLogger.sharedInstance().filter = logFilter
    GCKLogger.sharedInstance().delegate = self

    // MARK - GCKLoggerDelegate

    func logMessage(_ message: String, at level: GCKLoggerLevel, fromFunction function: String, location: String) {
        if (kDebugLoggingEnabled) {
            // Send SDK's log messages directly to the console.
            print("\(location): \(function) - \(message)")

        }
    }

    return true
}

最佳答案

我也在制作一个 Actor 应用程序。我遇到了同样的事情,这对我有用。事实证明,您需要告诉导航打开。

// initiates the navigation bar to place the chrome icon
    titleView = navigationItem.titleView
    rootTitleView = UIImageView(image: UIImage(named: "logo_castvideos.png"))
    castButton = GCKUICastButton(frame: CGRect(x: CGFloat(0), y: CGFloat(0),
                                               width: CGFloat(24), height: CGFloat(24)))
  castButton.isHidden = false
    castButton.tintColor = UIColor.white
    self.setNavigationBar()
    NSObject.setAccessibilityLabel("true")

关于ios - 我的代码是否未正确实现 google chromecast 按钮和流媒体功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54590025/

相关文章:

swift - 播放视频不是全屏,swift 3

Swift Segue 从 UIBarButtonItem

linux - linux可以用于chrome cast(chrome)开发吗?

android - 我们可以通过 Chromecast 向电视发送通知吗?

ios - 如何根据其内容调整 UITextView 的大小?

ios - 如何以编程方式在云工具包中标记可查询的记录类型

ios - 如果字符串包含某些字符,Swift 会删除扩展字符吗?

swift - 将所有项目放入一个 Collection View 行中

android - 当另一个应用程序开始转换时如何停止转换?

iOS 模拟器看起来模糊且像素化