iOS Swift - Preload AVAsset - ios

I have to make sure that I have fully loaded the videos before playing them. I went through the Apple documentation but couldn't find how to do it.
I tried AVAssetDownloadTask but I don't want to keep the files. I want them to be deleted after the app is closed. Is there a recommended method for this?
I need to make sure the videos are fully downloaded and ready to play. So AVPlayer's default behavior doesn't work for me

Related

Audiio fiiles inside an iOS application

Is there a way inside an iOS Swift app of mine, to access the sound files I already have available in my itunes library on the same device?
Browsing the net I came accross something called File-Sharing and the UIFileSharingEnabled key, but that does not seem to be quite what I am looking for.
The files? I’m not sure.. if so only those you downloaded or bought on iTunes. For access to Apple Music you probably want to look into MusicKit.
However, there’s a way to get MediaItems via MPMediaPickerController (docs)

How to fill metadata info for tvOS info panel when using Airplay?

I'm barely new to iOS.
I'm able to reproduce streams(no local video) via AVPlayer using Airplay.
Also, MPNowPlayingInfo and RemoteCommandManager are supported, using external medatada, not included into the streams.
But, I would like to fill the info panel with title, artwork, etc. on AppleTv/tvOS.
The image is part of WWDC17 talk titled "Now Playing and Remote 
 Commands on tvOS".
My question is not about tvOS apps, which the referenced talk is about, but about a iOS app that plays video via Airplay.
My guess is that the played AVAsset needs to have medatada, which currently would be empty.
I've been checking AVMutableMetaDataItem, but still don't understand if that's what I would need to use, nor how to do it.
Does anyone has any hint?
The WWDC 2019 Talk :( https://developer.apple.com/videos/play/wwdc2019/503/ ) which is about Delivering Intuitive Media Playback with AVKit speaks about using the external metadata during Airplay and how they have provided the API for iOS now which is similar to what was present on tvOS. (Refer from duration of 7 minutes in the Video mentioned above where they explain the same.) Hope this helps:)

ios swift store videos

I am doing a video Library app. I want store 6 videos locally in this app. When user download this app, it already had those 6 videos. Also, those videos might be replaced later by other videos if the app has been updated from server. So where should I put those videos? The sandbox document or other place?
The pre-uploaded videos will always be in your bundle, you have no method to replace it. All the other videos will be in your sandbox as it's the only place you can use.
You can have a look at on-demand-resource introduced in iOS9, which may be what you want.
The Documents folder is indeed the best place to store videos or other files that you want to persist between launches of the application.
Because cellular data can be expensive and to reduce initial download size, I recommend allowing the user to download the video files only after installing your app.
The concept I'm talking about can be seen by looking at this related question (code is in Objective-C, tho).

Apple Music Offline Files Have no URL?

It seems that the property MPMediaItemPropertyAssetURL on a MPMediaItem returns null when the file is one that was from Apple Music and has been made "available offline".
On the other hand, items from my original library which I uploaded to iTunes match/apple music and then make available offline don't seem to have this problem.
Is this a bug? Have I done something wrong? Anyone having similar issues?
It seems that Apple Music files are DRM-protected and subscription based, so probably Apple prohibits the use of references to these assets due to rights management.
Reference: https://forums.developer.apple.com/thread/7389
Things have changed a little and this isn't true anymore. MPMediaItemPropertyAssetURL is not nil on iOS 11 for songs saved offline via Apple Music but AVPlayer is unable to play them since they are still DRM protected. The same song returns MPMediaItemPropertyAssetURL nil on iOS 9.
If you are interested in checking for DRM protected songs or in playing such songs, you can read my detailed answer here: https://stackoverflow.com/a/47694472/4331787

Add Music to iOS programmatically

Let say I want to create an iOS app that download music files from the internet.
Is it possible then to put this music files on the Music Library so that I can play it?
It's not possible. The only way to add music to your library is through iTunes or through the iTunes Store app. Even if you did find a way, it'd probably be through some private API and you'd probably get rejected on the app store.
As Simon said, you won't get music into the native music library. You could however store the audio files and use the AVFoundation Framework (AVAudioPlayer class) to replay them. You could also possibbly use the AudioToolbox framework. Problem is you would have to implement your own music library and your own playback functionality.
Did I mention you have roughly a 0% chance of this app making it into the app store?
It is clearly possible though...even trivial...
Well, in terms of possibility, it is possible if you jailbreak your device, you'd need 2 tweaks to do it:
"Safari download enabler" or manager: to allow you to download files.
"Bride": allows you to import downloaded or saved mp3 files or mp4 video files to your iOS library.
I've been using it for a while and it works like magic
You can have private API/Library. Though I never tried, but you can.
Here is the another similar post:
Programmatically add content to music library

Resources