Skip to content

Commit

Permalink
Commit
Browse files Browse the repository at this point in the history
Fisrt Version
  • Loading branch information
AceDong0803 committed Mar 27, 2018
0 parents commit a076956
Show file tree
Hide file tree
Showing 28 changed files with 3,080 additions and 0 deletions.
Binary file added LameMp3EncodeDemo/.DS_Store
Binary file not shown.
Binary file added LameMp3EncodeDemo/Lame/.DS_Store
Binary file not shown.
1,342 changes: 1,342 additions & 0 deletions LameMp3EncodeDemo/Lame/include/lame/lame.h

Large diffs are not rendered by default.

Binary file added LameMp3EncodeDemo/Lame/libmp3lame.a
Binary file not shown.
415 changes: 415 additions & 0 deletions LameMp3EncodeDemo/LameMp3EncodeDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>LameMp3EncodeDemo.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
17 changes: 17 additions & 0 deletions LameMp3EncodeDemo/LameMp3EncodeDemo/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AppDelegate.h
// LameMp3EncodeDemo
//
// Created by AnDong on 2018/2/13.
// Copyright © 2018年 AnDong. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@end

51 changes: 51 additions & 0 deletions LameMp3EncodeDemo/LameMp3EncodeDemo/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// AppDelegate.m
// LameMp3EncodeDemo
//
// Created by AnDong on 2018/2/13.
// Copyright © 2018年 AnDong. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
17 changes: 17 additions & 0 deletions LameMp3EncodeDemo/LameMp3EncodeDemo/AudioPlayViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AudioPlayViewController.h
// LameMp3EncodeDemo
//
// Created by AnDong on 2018/3/15.
// Copyright © 2018年 AnDong. All rights reserved.
//

#import <UIKit/UIKit.h>

@class Mp3FileModel;

@interface AudioPlayViewController : UIViewController

@property (nonatomic,strong)Mp3FileModel *fileModel;

@end
117 changes: 117 additions & 0 deletions LameMp3EncodeDemo/LameMp3EncodeDemo/AudioPlayViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//
// AudioPlayViewController.m
// LameMp3EncodeDemo
//
// Created by AnDong on 2018/3/15.
// Copyright © 2018年 AnDong. All rights reserved.
//

#import "AudioPlayViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "Mp3FileModel.h"

@interface AudioPlayViewController ()<AVAudioPlayerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *playTimeLabel;
@property (weak, nonatomic) IBOutlet UIButton *playBtn;
@property (nonatomic,strong) AVAudioPlayer *player;
@property (nonatomic,strong) NSTimer *playStatusTimer;
@end

@implementation AudioPlayViewController


- (void)viewDidLoad {
[super viewDidLoad];

self.player = [[AVAudioPlayer alloc]initWithContentsOfURL:
[NSURL URLWithString:self.fileModel.mp3Path]
error:nil];
self.player.delegate = self;
//开始播放
[self.player prepareToPlay];
//播放
[self.player play];

[self startPlayStatusTimer];
}

- (void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
[self.player stop];
[self stopPlayStatusTimer];
}

- (IBAction)navBack:(UIButton *)sender {
[self dismissViewControllerAnimated:YES completion:^{

}];
}

- (void)updateTime{
NSTimeInterval currentTime = self.player.currentTime;
self.playTimeLabel.text = [self getFormatString:currentTime];
}

- (NSString *)getFormatString:(NSInteger)totalSeconds {
NSInteger seconds = totalSeconds % 60;
NSInteger minutes = (totalSeconds / 60) % 60;
NSInteger hours = totalSeconds / 3600;
if (hours <= 0) {
return [NSString stringWithFormat:@"%02ld:%02ld",(long)minutes, (long)seconds];
}
return [NSString stringWithFormat:@"%02ld:%02ld:%02ld",(long)hours, (long)minutes, (long)seconds];
}

- (void)startPlayStatusTimer{
if (!self.playStatusTimer) {
self.playStatusTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
[self.playStatusTimer setFireDate:[NSDate distantPast]];
}
}

- (void)stopPlayStatusTimer{
if (self.playStatusTimer) {
[self.playStatusTimer invalidate];
self.playStatusTimer = nil;
self.playTimeLabel.text = @"00:00";
}
}

#pragma mark - AVAudioPlayerDelegate

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer*)player successfully:(BOOL)flag{
//播放结束
[self stopPlayStatusTimer];
}

- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer*)player error:(NSError *)error{
//解码错误
}

- (void)audioPlayerBeginInteruption:(AVAudioPlayer*)player{
//处理中断
}

- (void)audioPlayerEndInteruption:(AVAudioPlayer*)player{
//处理中断结束
}


- (IBAction)playBtnClick:(UIButton *)sender {
//暂停播放
sender.selected = !sender.selected;

if (sender.selected) {
//暂停
[self.player pause];
[sender setTitle:@"开始播放" forState:UIControlStateNormal];
}
else{
//开始播放
[self.player play];
[sender setTitle:@"暂停" forState:UIControlStateNormal];
}
}


@end
Loading

0 comments on commit a076956

Please sign in to comment.