1

I see that for PHContentEditingInput (https://developer.apple.com/library/prerelease/ios/documentation/Photos/Reference/PHContentEditingInput_Class/index.html#//apple_ref/occ/instp/PHContentEditingInput/avAsset), the Video Asset stuff has been deprecated.

If I need to process videos, what should I be using instead?

(In particular, NSURL from PHAsset, they used that deprecated function here. Is there something else I could use that's not deprecated but can attain the NSURL?)

EDIT: So... after I read up a bit on AVFoundation framework... How exactly do we convert our PHAsset into an AVURLAsset without using the deprecated method?

Community
  • 1
  • 1
dcheng
  • 1,673
  • 1
  • 9
  • 19

4 Answers4

2

The documentation hasn't been updated for iOS 9 (yet, I'd assume). But if you look in the PHContentEditingInput.h header (or generated Swift interface) in Xcode, though, you'll see that it's just a renaming — avAsset is deprecated in favor of audiovisualAsset. It still returns an AVAsset object, which you can then process using AVFoundation.

rickster
  • 118,448
  • 25
  • 255
  • 308
0

If I need to process videos, what should I be using instead

It depends what you mean by "process", I suppose, but in general you should be using AVFoundation.

matt
  • 447,615
  • 74
  • 748
  • 977
  • Oh wait... did they remove videos out of the Photos framework and provide a whole new framework for them? And by process, I mean whatever you were able to do with avAsset before. I just started so I'm not particularly sure what I need for this. – dcheng Jun 15 '15 at 23:59
  • You presumably wouldn't be using PHContentEditingInput in this situation. It's for editing photos, especially in a photos extension. – matt Jun 16 '15 at 00:06
  • So currently I'm iterating through my Assets, and some happen to be videos... Those are currently stored as PHAssets. How do I get them to become AVURLAssets without using that method? – dcheng Jun 16 '15 at 00:08
  • 1
    I have a suspicion that this will turn out to have something to do with the new PHAssetResource class, but I have not watched the new WWDC video on this topic yet and the docs have not been updated, so that's just a guess. – matt Jun 16 '15 at 00:17
0

What kind of URL are you looking for from the AVURLAsset object? There are two variants, and the distinction is always relevant (take the URL generated by UIImagePickerController versus the one used by AVAssetReader/Writer, for example). Here they are:

[[PHImageManager defaultManager] requestAVAssetForVideo:phAsset options:nil resultHandler:^(AVAsset *avAsset, AVAudioMix *audioMix, NSDictionary *info) {
    NSURL *url = (NSURL *)[[(AVURLAsset *)avAsset URL] fileReferenceURL];
    NSLog(@"url = %@", [url absoluteString]);
    NSLog(@"url = %@", [url relativePath]);
 }];

Whereas phAsset is the PHAsset object, and avAsset is the resulting AVAsset object generated by PHImageManager, the output to the console from the above code will produce, for example:

2016-04-16 01:15:40.155 ChromaEpsilon[3423:933358] url = file:///.file/id=16777218.8262005
2016-04-16 01:15:40.155 ChromaEpsilon[3423:933358] url = /private/var/mobile/Media/DCIM/108APPLE/IMG_8421.MOV

There's more than just these two, I believe, but start here.

James Bush
  • 1,347
  • 11
  • 17
0

For Swift 2.0

Import File

import AVKit

From PHAsset

static func playVideo (view:UIViewController, asset:PHAsset) {

        guard (asset.mediaType == PHAssetMediaType.Video)

            else {
                print("Not a valid video media type")
                return
        }

        PHCachingImageManager().requestAVAssetForVideo(asset, options: nil, resultHandler: {(asset: AVAsset?, audioMix: AVAudioMix?, info: [NSObject : AnyObject]?) in

            let asset = asset as! AVURLAsset   // you are looking for

            dispatch_async(dispatch_get_main_queue(), {

                let player = AVPlayer(URL: asset.URL)
                let playerViewController = AVPlayerViewController()
                playerViewController.player = player
                view.presentViewController(playerViewController, animated: true) {
                    playerViewController.player!.play()
                }
            })
        })
    }
Sazzad Hissain Khan
  • 29,428
  • 20
  • 134
  • 192