2015-01-01 2 views
-2

서버에서 노래를 다운로드하고 싶지만 전체 노래를 다운로드하고 싶지 않으므로 첫 번째 90 년대를 다운로드하고 싶습니다. 사용자가 첫 번째 80 년대를 듣는다면이 노래의 나머지 부분을 요청할 것입니다. . 그렇지 않으면이 노래의 나머지 부분은 전혀 다운로드 할 필요가 없습니다.mp3 파일을 몇 초 동안 재생할 수 있습니까?

요청 헤더에 range 매개 변수가 있습니다. 다운로드해야하는 노래 부분을 결정하기 위해 최소 - 최대 바이트를 전달할 수 있습니다.

그렇다면 90 곡을 재생할 수있는 노래의 바이트 수는 어떻게 알 수 있습니까 ??

+0

을보십시오. mp3가 인코딩되는 방식은 단순한 방정식이 아닙니다. – matt

+0

질문이 왜 왜곡되어 온라인 스트리밍을 시도해보십시오. – sanjeet

답변

0

인코딩 된 파일의 비트 전송률 (파일 헤더를 읽음으로써 얻을 수 있음)을 알 필요가 있지만 바이트 수를 얻기 위해 곱하면 많은 MP3가 가변 비트 전송률로 인코딩됩니다. Matt의 말에 따르면, 솔루션은 매우 복잡합니다.

그러나 약간 접근 방식을 변경 한 경우에는 훨씬 간단한 방법으로 비슷한 달성 할 수 - 오히려 일정 시간 걱정, 단지

단순히 바이트의 적절한 수를 선택 바이트 수를 읽어 처음에는이 데이터를 다 써 버릴 때 파일의 나머지 부분을 읽으십시오.

1 메가 바이트는 128kbs의 고정 비트 전송률로 인코딩 된 MP3 파일의 60 초를 조금 넘습니다. 고정 비트 전송률의 경우 256kbs 파일의 경우 약 30 초, 30kHz 가변 비트 전송률 (VBR)이기 때문에 처음에는 읽기에 적당합니다.

1

당신은 할 수 없습니다이

-(void)playselectedsong{ 

    AVPlayer *player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:urlString]]; 
    self.songPlayer = player; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(playerItemDidReachEnd:) 
               name:AVPlayerItemDidPlayToEndTimeNotification 
               object:[songPlayer currentItem]]; 
    [self.songPlayer addObserver:self forKeyPath:@"status" options:0 context:nil]; 
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateProgress:) userInfo:nil repeats:YES]; 



} 
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 

    if (object == songPlayer && [keyPath isEqualToString:@"status"]) { 
     if (songPlayer.status == AVPlayerStatusFailed) { 
      NSLog(@"AVPlayer Failed"); 

     } else if (songPlayer.status == AVPlayerStatusReadyToPlay) { 
      NSLog(@"AVPlayerStatusReadyToPlay"); 
      [self.songPlayer play]; 


     } else if (songPlayer.status == AVPlayerItemStatusUnknown) { 
      NSLog(@"AVPlayer Unknown"); 

     } 
    } 
} 

- (void)playerItemDidReachEnd:(NSNotification *)notification { 

// code here to play next sound file 

}