相关疑难解决方法(0)

如何在后台Swift中播放音频?

如你所见,我正在播放音频广播.但是,当我按下主页按钮退出应用程序流停止或我听不到.如何在后台继续流式传输并从锁定屏幕中进行监听?

ViewController.Swift

import UIKit
import AVFoundation
import MediaPlayer
import GoogleMobileAds


    class ViewController: UIViewController, GADInterstitialDelegate {

        @IBOutlet weak var exitMapButton: UIButton!
        @IBOutlet weak var radarMap: UIWebView!
        var interstitial: GADInterstitial!
        func createAndLoadInterstitial() -> GADInterstitial {
            var interstitial = GADInterstitial(adUnitID: "ca-app-pub-5378899862041789/2782958552")
            interstitial.delegate = self
            interstitial.loadRequest(GADRequest())
            return interstitial
        }

        func getAd(){
            if (self.interstitial.isReady)
            {
                self.interstitial.presentFromRootViewController(self)
                self.interstitial = self.createAndLoadInterstitial()
            }
        }
        @IBOutlet weak var ataturkButton: UIButton!
        @IBOutlet weak var sabihaButton: UIButton!
        @IBOutlet weak var esenbogaButton: UIButton!
        @IBOutlet weak var weatherButton: UIButton!
        @IBOutlet weak var statusLabel: …
Run Code Online (Sandbox Code Playgroud)

audio avfoundation ios swift

45
推荐指数
3
解决办法
3万
查看次数

iOS 媒体播放控件通知

我是 iOS 新手,正在使用 Flutter 开发跨平台应用程序。我正在尝试从网络 URL 播放音频,我发现它可以使用AVPlayer. 当应用程序在前台和后台时播放音频,但我可以像这样显示媒体播放控件:在此处输入图片说明.

我使用let mediaController = MPMusicPlayerController.applicationMusicPlayer然后调用self.mediaController.beginGeneratingPlaybackNotifications(),还提供播放信息MPNowPlayingInfoCenter.default().nowPlayingInfo = mediaInfo并在self.registerCommands()方法中为远程命令中心设置目标。

我做了很多研究,但没有找到问题的运气,正如我之前所说的,我是 ios 新手。

应用程序委托

import UIKit
import Flutter
import AVFoundation
import MediaPlayer

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {

    static let CHANNEL = "APP_CHANNEL"
    let mPlayer = AudioPlayer()
    let mediaController = MPMusicPlayerController.applicationMusicPlayer

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

    self.requestNotificationPermission(application: application)

    let controller : FlutterViewController = window?.rootViewController as! FlutterViewController …
Run Code Online (Sandbox Code Playgroud)

ios avplayer mpnowplayinginfocenter swift mpremotecommandcenter

6
推荐指数
2
解决办法
2093
查看次数