我已经实现了Google chrome Cast,并以编程方式添加了按钮,但是设备未显示按钮和流式播放功能。我的代码编写不正确吗?
我已经尝试过本指南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
}
答案 0 :(得分:0)
我也在制作演员表应用程序。我遇到了同样的事情,这对我有用。事实证明,您需要告诉导航打开。
// 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")