ios-Audio and video

Source: Internet
Author: User

First, the video
    1. The video player needs to add mediaplayer.framework.
    2. Video playback mainly provides two classes, one MPMoviePlayerController, and the other is Mpmovieplayerviewcontroller.
    3. Video resources can be obtained locally or from the server

MPMoviePlayerController playing local video resources

MPMoviePlayerController Play network resources (the server is built for itself, the address is not available)

You can add a notification that notifies you when the video has finished playing and removes the view from the interface.

Mpmovieplayerviewcontroller Playing video Resources

:

Mpmovieplayerviewcontroller How to make the video cross-screen playback.

Horizontal screen playback, need to inherit mpmovieplayerviewcontroller this class. Suppose Mympmovieplayerviewcontroller inherits this class.

We need to implement two methods in Mympmovieplayerviewcontroller.

Then implement the following code:

For:

Second, audio

Audio words we need frame avfoundation.framework

Audio, it is generally necessary to use the progress bar to show the progress of audio playback.

123456789101112 @interfaceViewController : UIViewController{    //音频播放器    AVAudioPlayer * _audioPalyer;    IBOutletUISlider *_slider;    float currentProgress;    NSTimer*_timer;}- (IBAction)playButton:(id)sender;- (IBAction)stopButton:(id)sender;@end
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 - (void)viewDidLoad{    [superviewDidLoad];    // Do any additional setup after loading the view, typically from a nib.    _slider.value = 0.0;} - (IBAction)playButton:(id)sender{   _timer = [NSTimerscheduledTimerWithTimeInterval:1.0f target:selfselector:@selector(moveSlide) userInfo:nilrepeats:YES];        NSString*path = [[NSBundlemainBundle]pathForResource:@"1"ofType:@"mp3"];    NSData*data = [NSDatadataWithContentsOfFile:path];    _audioPalyer = [[AVAudioPlayer alloc]initWithData:data error:nil];    [_audioPalyer play];        _slider.maximumValue = _audioPalyer.duration;    [_slider addTarget:self action:@selector(changeSlide) forControlEvents:UIControlEventValueChanged];}-(void)changeSlide{    _audioPalyer.currentTime = _slider.value;}-(void)moveSlide{    _slider.value = _audioPalyer.currentTime;}- (IBAction)stopButton:(id)sender{    UIButton *button = (UIButton *)sender;       if(button.tag == 0)    {        [_audioPalyer pause];        [button setTitle:@"继续播放"forState:UIControlStateNormal];        button.tag = 1;        [_timer invalidate];        _timer = nil;    }    else    {        [_audioPalyer play];        [button setTitle:@"暂停"forState:UIControlStateNormal];        button.tag = 0;        [_slider addTarget:selfaction:@selector(changeSlide) forControlEvents:UIControlEventValueChanged];    }}

:

ios-Audio and video

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.