Post marked as unsolved
13
Views
I want to set "ringer and alerts" sound in code.
MPVolumeView() seems like to control the system volume only. I have some sound effect(by invoking "AudioServicesPlaySystemSound(SystemSoundID:)") affected by "ringer and alerts" in my app. Even when the system volume is max, my app sound effect is still mute if "ringer and alerts" sound is mute. I have to tune "ringer and alerts" by "setting-sounds-ringer and alerts" manually.
Is there any programable way to set it? Any help will be greatly appreciated.
Post marked as unsolved
10
Views
So I am using the sample code that was provided by Apple in 2020, however it seems that the code is no longer correct.
As I am getting the following error:
Cannot call value of non-function type 'CPNowPlayingTemplate'
Remove '()'
However when I do remove it the app fires up fine, minus the now playing information.
I am wondering what do I need to do to get the now playing information which my iOS app does display, to send over to the CarPlay screen.
I was told - "All you need is this template and then apple does everything in the background."
Clearly that's wrong, because Apple would never make something be so easy.
So I know I am going to have to add buttons, album art extra extra. But I don't know how to go about this, as I normally use SwiftUI.
import Foundation
import CarPlay
class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene,
didConnect interfaceController: CPInterfaceController) {
if #available(iOS 14.0, *) {
let nowPlayingTemplate = CPNowPlayingTemplate.shared
let rateButton = CPNowPlayingPlaybackRateButton() {_ in
// Change the playback rate!
}
nowPlayingTemplate.updateNowPlayingButtons([rateButton])
} else {
// Fallback on earlier versions
}
}
}
Side note: the sooner Apple allows SwiftUI to take over this the better.
So key questions:
How to print song information on this screen
How to add pause and play button.
I have included my MediaPlayer.swift file so you can see I use MPNowPlayingInfoCenter
MediaPlayer.swift - https://developer.apple.com/forums/content/attachment/0caa76cd-53d3-439c-9a86-37703dc20348
Post marked as unsolved
173
Views
I'm using cloudFront lambda to encrypt urls and AVURLAssetHTTPHeaderFieldsKey through md5 token to decrypt it with AVPlayer.
The problem is that AVPlayer is working fine but when trying to cast the video with AirPlay, it flashs for a second then nothing is casted.
Thanks,
Post marked as unsolved
97
Views
Hi,
I'm trying set playbackState like
swift
MPNowPlayingInfoCenter.default().playbackState = .playing
But I receive an error in console.
[NowPlaying] [MRNowPlaying] Ignoring setPlaybackState because application does not contain entitlement com.apple.mediaremote.set-playback-state for platform
I tried to add it to applications *.entitlements file:
xml
keycom.apple.mediaremote.set-playback-state/key
true/
But after that I cannot even build my application due to signing error:
Provisioning profile "iOS Team Provisioning Profile: app.name" doesn't include the com.apple.mediaremote.set-playback-state entitlement.
I use a free development certificate if it is important. Xcode version is 12.4.
Did anyone face with same issue? What do I wrong? What should I do to solve an issue?
Thanks for any help!
Post marked as unsolved
28
Views
We have a use case where we'd like to disable picture in picture for user accounts with certain entitlements. I know tvOS has the built in PIP button on the remote. But can we still disable pip for our app?
Post marked as unsolved
100
Views
Hello,
Why there is no speed control on the video player? Having no option, I had to download the clip, and then play it on my end, with a player that has a speed control.
https://developer.apple.com/videos/play/wwdc2020/10153/
Sometimes I feel like watching a video on x2 speed, sometimes I feel like watching it on whatever speed. Add this option please.
Also you may have a keyframes of the story, like contents of a book, for faster navigation in a lengthy videos.
Best regards
Post marked as unsolved
177
Views
I am using a media player to play songs. Setting Queue firstly and start playing songs works fine. While if I try to change the queue when one song is playing queue does not get changed. Until I call the MediaPlayer Play function again.
Calling the Media Player Play function whereas freezes the app for seconds.
Tried several ways but nothing works. Do let me know how we can change the queue of the media player while not disturbing the ongoing song.
Thanks in advance.
Post marked as unsolved
146
Views
I have an application that as part of it's functionality, reproduce music from the music library using the AVPlayerItem.
it's working fine on iOS but on the Macbook with M1 processor the audio is not loading.
Plist already contains the items:
NSAppleMusicUsageDescription & NSAppTransportSecurity
Post marked as unsolved
241
Views
I’m converting a MusicKit app from iOS to macOS with Catalyst but can’t get the player to work. The app works flawlessly on iOS but I get the following error in my console on macOS whenever the MPMusicPlayer tries to manipulate the queue by adding a song with a store id
[SDKPlayback] Failed to obtain remoteObject: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named com.apple.Music.MPMusicPlayerApplicationControllerInternal was invalidated." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.apple.Music.MPMusicPlayerApplicationControllerInternal was invalidated.}
Both the player, setQueue and play methods are according to the documentation supported on Mac Catalyst 13+:
https://developer.apple.com/documentation/mediaplayer/mpmusicplayercontroller
https://developer.apple.com/documentation/mediaplayer/mpmusicplayercontroller/1624253-setqueue
https://developer.apple.com/documentation/mediaplayer/mpmusicplayercontroller/2582424-preparetoplay
https://developer.apple.com/documentation/mediaplayer/mpmediaplayback/1616255-play
Post marked as unsolved
86
Views
I am creating an IOS application to play music using my custom player and I am fetching the music from iTunes music. But the assetURL for most of the songs is nil and I am not able to play these songs. I have an active subscription of iTunes music and songs are downloaded into my iMusic app for offline purpose.
Any idea what I need to add in order to play all iTunes songs into my application?
Post marked as unsolved
79
Views
Hello,
I have followed this approach (https://developer.apple.com/documentation/avfoundation/avplayeritemmetadatacollector) to get the daterange metadata from my HLS manifest, which in my case represent ad-inserted. With that in mind and with a proper time evaluation I could know when an user reach an ad. Unfortunately, this require to check at least every second if the user reach the ad which I found it not performance-wise.
Is there any event/callback that is trigger or call if the AVPlayer reach a daterange?
Thanks in advance.
Post marked as unsolved
100
Views
I'm writing a Mac Catalyst app that displays graphics in a window while trying to play Apple Music content in the background.
However, if the Music.app is not already running, as soon as my app goes to stream a song (which does successfully play) the Music.app's window pops-up on screen, obscuring my app's window!
Is there something simple I can do to force Music.app to stay iconified?
I'm trying to avoid hacking this. (...like having to use "scripting bridge," if that's even still possible, or forcing a hotkey to close the window, or something similarly kludgey.)
Thanks for any ideas!
Post marked as unsolved
117
Views
Hi all,
Hope you're doing well today.
I'm working with the MPMediaItemPropertyLyrics variable provided by the MediaPlayer framework. I'm accessing the user's Apple Music library. The content that I'm playing within my application are all downloaded and stored locally.
I'm utilizing the MPMediaItemPropertyLyrics variable which is type NSString, however no text is returned. I can validate that there are lyrics by comparing the same MediaItem object within Apple's Music application. I have an If else statement where if there are no lyrics available, I return a "Lyrics Not Available" text to the UITextView. However while stepping through the runtime debugger I can see that the function is returning that there are lyrics.
Here's my code within the implementation file. (Yes objective-c, though I'm open to Swift resolutions as well).
MPMediaItem *currentItem = [self.musicPlayer nowPlayingItem];
NSString *MPlyrics = [currentItem valueForProperty:MPMediaItemPropertyLyrics];
if (MPlyrics) {
NSLog(@"Here are the Lyrics: %@",MPlyrics);
self.lyrics.text = MPlyrics;
} else {
NSLog(@"No Lyrics");
self.lyrics.text = @"Lyrics Not Available";
}
Here's the property that I have in the header file
@property (nonatomic, readonly) NSString *lyricsString;
I've tried setting the property to (nonatomic, readonly, copy).
Am I doing wrong here? Am I missing something? Would love your thoughts everyone! Let me know if you have any questions.
Post marked as solved
242
Views
I am trying to show AVPlayer controls and audio info on the locked screen, but it is not working. Please consider example below.
swift
import SwiftUI
import MediaPlayer
import AVFoundation
class ViewModel: ObservableObject {
@Published var isPlaying = false
private let audioSession = AVAudioSession.sharedInstance()
private let player = AVPlayer()
init() {
if let path =
Bundle.main.path(forResource: "5.mp3", ofType: nil) {
let asset = AVAsset(url: URL(fileURLWithPath: path))
let playerItem = AVPlayerItem(asset: asset)
player.replaceCurrentItem(with: playerItem)
}
try! self.audioSession.setCategory(AVAudioSession.Category.playback)
try! self.audioSession.setActive(true)
setupRemoteTransportControls()
setupNowPlaying()
}
func setupRemoteTransportControls() {
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.playCommand.isEnabled = true
commandCenter.playCommand.addTarget { [unowned self] event in
if !self.isPlaying {
self.play()
return .success
}
return .commandFailed
}
commandCenter.pauseCommand.isEnabled = true
commandCenter.pauseCommand.addTarget { [unowned self] event in
if self.isPlaying {
self.pause()
return .success
}
return .commandFailed
}
}
func setupNowPlaying() {
// Define Now Playing Info
var nowPlayingInfo = [String : Any]()
nowPlayingInfo[MPMediaItemPropertyTitle] = "My Movie"
if let image = UIImage(named: "lockscreen") {
nowPlayingInfo[MPMediaItemPropertyArtwork] =
MPMediaItemArtwork(boundsSize: image.size) { size in
return image
}
}
nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = player.currentItem?.currentTime().seconds
nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = player.currentItem?.asset.duration.seconds
nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = player.rate
// Set the metadata
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
}
func play() {
isPlaying.toggle()
player.play()
}
func pause() {
isPlaying.toggle()
player.pause()
}
}
struct ContentView: View {
@StateObject private var viewModel = ViewModel()
var body: some View {
Button(action: {
if viewModel.isPlaying {
viewModel.pause()
} else {
viewModel.play()
}
}, label: {
Image(systemName: viewModel.isPlaying ? "pause" : "play")
})
}
}
Does anybody has any clue what am i missing to make it work with SwiftUI?
I also tried to add beginReceivingRemoteControlEvents but it does not make any difference
swift
struct PlayerApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) - Bool {
application.beginReceivingRemoteControlEvents()
return true
}
}
The audio is playing ok with the locked screen, it is just there is no playback controls and media info
Tested with Xcode 12.4, iphone-12 simulator
Post marked as unsolved
106
Views
We have the following subtitle having U+202B (right to left embedding) code to force right to left text.
صحيح، لكن في هذه الحالة...
This code was added to enable RTL rendering on a certain platform that renders text LTR by default.
However, after adding the code, we observe that the subtitles are rendered LTR in AVPlayer. If the U+202B code is removed then the subtitles are rendered RTL (as seen above)
This issue is seen only when punctuations (or similar characters) are present
Is there anyway I can make the AVPlayer ignore the U+202B code?