iOS 백그라운드 오디오 플레이 컨트롤 예제

2020. 5. 17. 05:59아이폰 개발

완벽하지는 않지만, 일반적인 iOS용 뮤직 플레이 앱들처럼 싱크 컨트롤 센터와 연동하도록 만드는 예제이다.

https://medium.com/@quangtqag/background-audio-player-sync-control-center-516243c2cdd1

 

Background Audio Player Sync Control Center

In this tutorial, you will create a player with capability of play audio in background mode and synchronize with music controls in Control…

medium.com

다음 예제는 iOS 오디오 플레이어 컨트롤 센터와 연동이 되는 것은 아니지만, 간단하게 백그라운드로 음악을 시작/종료 할 수 있는 예제이다.

https://www.zerotoappstore.com/how-to-add-background-music-in-swift.html

 

How To Add Background Music In Swift? - Zero To App Store

Adding music is a common request for mobile video games. When I built my first iOS game, I had to research this problem and find its solution. How To Add Background Music In Swift With Code Examples Create a class called MusicPlayer.swift. import Foundatio

www.zerotoappstore.com

이전/다음 버튼을 눌렀을 때 처리하는 방법

import MediaPlayer

let rcc = MPRemoteCommandCenter.shared()

let skipBackwardCommand = rcc.skipBackwardCommand
skipBackwardCommand.isEnabled = true
skipBackwardCommand.addTarget(handler: skipBackward)
skipBackwardCommand.preferredIntervals = [42]

let skipForwardCommand = rcc.skipForwardCommand
skipForwardCommand.isEnabled = true
skipForwardCommand.addTarget(handler: skipForward)
skipForwardCommand.preferredIntervals = [42]

func skipBackward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus {
    guard let command = event.command as? MPSkipIntervalCommand else {
        return .noSuchContent
    }

    let interval = command.preferredIntervals[0]

    print(interval) //Output: 42

    return .success
}

func skipForward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus {
    guard let command = event.command as? MPSkipIntervalCommand else {
        return .noSuchContent
    }

    let interval = command.preferredIntervals[0]

    print(interval) //Output: 42

    return .success
}

https://stackoverflow.com/questions/20591156/is-there-a-public-way-to-force-mpnowplayinginfocenter-to-show-podcast-controls

 

Is there a public way to force MPNowPlayingInfoCenter to show podcast controls?

I would like Control Center (via MPNowPlayingInfoCenter) to show the forward 15 seconds / back 15 seconds controls that Apple shows with podcasts, like so: The utter lack of documentation tells m...

stackoverflow.com

다음은 오디오간 우선 순위에 관하여 정리된 레퍼런스이다.

https://steemit.com/kr/@babysloth/ios-dev-avaudiosession-programming-guide-1

 

[iOS-Dev] AVAudioSession Programming Guide 내맘대로 번역 # 1 — Steemit

App개발 중 Background 노래가 재생되는 상태에서 AVPlayer, Recorder 등을 사용하는 경우 재생되던 노래가 종료되는 현상이 있어서, Guide를 정리하면서 공부하려고 합니다. 혹시나… by babysloth

steemit.com