IOS, multimedia related

Source: Internet
Author: User

1. Local Audio playback

2. Local video playback

Local audio playback

Import Header File

#import <AVFoundation/AVFoundation.h>

#import <MediaPlayer/MediaPlayer.h>

Import "ViewController.h"

@interface Viewcontroller ()

Avaudioplayer to be a global variable to play

@property (strong,nonatomic) Avaudioplayer *audioplayer;

@end

@implementation Viewcontroller

@synthesize Audioplayer=_audioplayer;

-(void) Viewdidload {

[Super Viewdidload];

[Self.view Setbackgroundcolor:[uicolor Whitecolor];

[Self.navigationitem settitle:@ "audio"];

//Play audio; Note: If you click Stop, then make sure the player is newly created, otherwise there will be some inexplicable problems

[Self.getaudioplayer play];

}

/**

* Create an audio player

*return Audio Player

*/

-(Avaudioplayer *) getaudioplayer{

NSString *path=[[nsbundle Mainbundle] pathforresource:@ "Too Late for Love" oftype:@ "MP3"];

Nsurl *url=[nsurl Fileurlwithpath:path];

//Create a player

_audioplayer=[[avaudioplayer alloc] Initwithcontentsofurl:url Error:nil];

//volume 0.0-1.0 between

_audioplayer.volume=0.2;

//Cycle times

_audioplayer.numberofloops=1;

//Playback position

_audioplayer.currenttime=0.0;

//channel number

Nsuinteger channels=_audioplayer.numberofchannels;//Read-only property

//Duration

Nstimeinterval duration=_audioplayer.duration;//Get Duration

//Assign the required resources to play and add them to the internal play queue

[_audioplayer Preparetoplay];

return _audioplayer;

}

@end

Local video playback

Import Header File

#import <AVFoundation/AVFoundation.h>

#import <MediaPlayer/MediaPlayer.h>

Import "ViewController.h"

@interface Viewcontroller ()

Video Playback Controller

@property (strong,nonatomic) MPMoviePlayerController *movieplayer;

@end

@implementation Viewcontroller

@synthesize Movieplayer=_movieplayer;

-(void) Viewdidload {

[Super Viewdidload];

[Self.view Setbackgroundcolor:[uicolor Whitecolor];

[Self.navigationitem settitle:@ "video"];

//Play Video

[Self.getmovieplayer play];

}

/**

* Create a video controller

*return Video Controller

*/

-(MPMoviePlayerController *) getmovieplayer{

NSString *path=[[nsbundle Mainbundle] pathforresource:@ "DotA2 official propaganda film" oftype:@ "mp4"];

Nsurl *url=[nsurl Fileurlwithpath:path];

_movieplayer=[[mpmovieplayercontroller alloc] Initwithcontenturl:url];

_movieplayer.view.frame=self.view.frame;

//Automatic adjustment of the length and width

_movieplayer.view.autoresizingmask=uiviewautoresizingflexiblewidth| Uiviewautoresizingflexibleheight;

[Self.view Addsubview:_movieplayer.view];

return _movieplayer;

}

IOS, multimedia related

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.