2017-01-10 4 views
-1

私はiOSアプリケーションの開発から新しく、私の要件は、再生中に進行スライダにアクセスし、適切な開始時間と終了時間を表示する必要があり、プレーヤーはURLストリーミングで作業していますこの問題を解決するために、サンプルコードを提供するのを手伝ってください。ありがとうございます。オーディオプレーヤープログレッシブスライダーをタイマーで目的のCに表示

+0

このURLを確認するhttp://stackoverflow.com/questions/27970317/how-to-pause-an-audio-and-its-timer-slider-in-ios –

答えて

0

enter image description here以下のコードを確認してください。私は2

ViewController.h

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController 
@end 

ViewController.mが

#import "ViewController.h" 
#import <AVFoundation/AVFoundation.h> 

@interface ViewController() 
{ 
    IBOutlet UISlider  *sliderView; 
    IBOutlet UILabel  *lblTimeInterval; 
    AVAudioPlayer   *avpPlayer; 
} 
@end 

@implementation ViewController 
@synthesize strName; 
@synthesize strTitle; 
@synthesize trackCount; 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    //First comment added to Proj. 
    //New Branch one is created by Team. 

} 


- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 


- (IBAction)progrssSlider { 
    avpPlayer.currentTime = sliderView.value; 
} 

- (void)updateTime:(NSTimer *)timer { 
    sliderView.value = avpPlayer.currentTime; 

    lblTimeInterval.text = [NSString stringWithFormat:@"%f",sliderView.value]; 

} 

- (IBAction)pressPlayButton:(id)sender { 

    //Read sound file from resource folder 
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sample.mp3" ofType:nil]]; 


    //Initialize AVAudioPlayer 
    NSError *error; 
    avpPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 

    //Check Player is initialized 
    if (!avpPlayer){ 
     NSLog(@"Error: %@", error); 
    } 
    else 
    { 
     [avpPlayer prepareToPlay]; 
     sliderView.maximumValue = [avpPlayer duration]; 
     sliderView.value = 0.0; 

     [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES]; 
     [avpPlayer play]; 
    } 


} 

@end 

時間を表示するようにUILAbelを定義してくださいXcodeの8ベータ版でテストしている、UISliderはスライダーを更新しXIBのボタンを再生します。

これがうまくいくと思います。

関連する問題