IOS get device local audio and video

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size:18px;">1. Retrieval of audio and video</span></p></p><p><p><span style="font-size:18px;"></span></p></p><pre name="code" class="objc"><pre name="code" class="objc">Phfetchoptions *allphotosoptions; @property (nonatomic, Strong) phfetchresult *assetsfetchresults;if ( Allphotosoptions = = Nil) { allphotosoptions = [[phfetchoptions alloc] init]; Allphotosoptions.sortdescriptors = @[[nssortdescriptor sortdescriptorwithkey:@ "creationdate" ascending:YES]]; } Self.assetsfetchresults = [phasset Fetchassetswithmediatype:phassetmediatypeimage options:allPhotosOptions];</pre></pre><p><p></p></p><p><p></p></p><p><p><span style="font-size:18px;">Where <span style="font-family:SimSun;">Assetsfetchresults stores all the picture information,</span><span style="font-family: SimSun;">phassetmediatypeimage for the type of search image, the same search for other classes can be based on</span></span></p></p><p><p><span style="font-size:18px;"><span style="font-family: SimSun;"></span></span></p></p><pre code_snippet_id="1608891" snippet_file_name="blog_20160313_2_5187889" name="code" class="objc"><pre code_snippet_id="1608891" snippet_file_name="blog_20160313_2_5187889" name="code" class="objc"><span style="font-size:18px;">typedef ns_enum (nsinteger, Phassetmediatype) { phassetmediatypeunknown = 0, phassetmediatypeimage = 1, phassetmediatypevideo = 2, phassetmediatypeaudio = 3,} Ns_enum_available_ios (8_0);</span></pre></pre><span style="font-size:18px;"><span style="font-size:18px;">2. Get the picture uiimage</span></span><p><p></p></p><p><p><span style="font-size:18px;"><span style="font-family: SimSun;"></span></span></p></p><pre code_snippet_id="1608891" snippet_file_name="blog_20160313_3_346104" name="code" class="objc"><pre code_snippet_id="1608891" snippet_file_name="blog_20160313_3_346104" name="code" class="objc"><span style="font-size:18px;">[[phcachingimagemanager defaultmanager] Requestimageforasset:asset Targetsize:assetgri Dthumbnailsize Contentmode:phimagecontentmodeaspectfill Options:nil resulthandler:^ (UIImage *result, nsdictionary *info) { Set the cell ' s thumbnail image if It's still showing the same asset. If ([cell.representedassetidentifier isEqualToString:asset.localIdentifier]) { Cell.thumbnailimage = result; } }];</span></pre></pre><span style="font-size:18px;"><span style="font-size:18px;">Asset is a phasset <span style="font-family: SimSun;">in Assetsfetchresults</span> <span style="font-family: SimSun;">,</span><span style="font-family: SimSun;">targetsize is to get the size of the picture, this is set according to the way you display, if you need to get pictures of other information such as the title can be used </span><span style="font-family: SimSun;"><br></span><span style="font-family: SimSun;"></span></span></span><pre code_snippet_id="1608891" snippet_file_name="blog_20160313_4_5504317" name="code" class="objc"><pre code_snippet_id="1608891" snippet_file_name="blog_20160313_4_5504317" name="code" class="objc">[phasset valueforkey:@ "filename"];</pre></pre><p><p><span style="font-size:18px;"><span style="font-family: SimSun;">3. Play Video</span></span></p></p><p><p><span style="font-size:18px;"><span style="font-family: SimSun;"></span></span></p></p><pre code_snippet_id="1608891" snippet_file_name="blog_20160313_5_4250581" name="code" class="objc"><pre code_snippet_id="1608891" snippet_file_name="blog_20160313_5_4250581" name="code" class="objc">-(void) setvideoasset: (phasset *) videoasset{ _videoasset = videoasset; [[phimagemanager defaultmanager] requestplayeritemforvideo:_videoasset Options:nil resultHandler:^ (AVPlayerItem * _ Nullable playeritem, nsdictionary * _nullable info) { self.currentitem = playeritem; [self.player replaceCurrentItemWithPlayerItem:self.currentItem]; [self.currentitem addobserver:self forkeypath:@ "status" options:nskeyvalueobservingoptionnew context:nil]; }];}</pre></pre><br><br><p><p></p></p><span style="font-size:18px;"><span style="font-size:18px;"><span style="font-family: SimSun;"><br><br><br><br></span></span></span><p><p></p></p><span style="font-size:18px;"><span style="font-size:18px;"><br></span></span><br><p><p>IOS get device local audio and video</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.