diff --git a/Plugins/WMA/WMADecoder.h b/Plugins/WMA/WMADecoder.h index 2819e8cf3..047a72de9 100644 --- a/Plugins/WMA/WMADecoder.h +++ b/Plugins/WMA/WMADecoder.h @@ -22,6 +22,7 @@ int numFrames; int samplePos; + int streamIndex; AVFormatContext *ic; AVCodecContext *c; AVCodec *codec; @@ -32,7 +33,7 @@ int channels; float frequency; long totalFrames; - + long framesPlayed; } @end diff --git a/Plugins/WMA/WMADecoder.m b/Plugins/WMA/WMADecoder.m index c10f11abc..537a528dc 100644 --- a/Plugins/WMA/WMADecoder.m +++ b/Plugins/WMA/WMADecoder.m @@ -70,14 +70,21 @@ int lockmgr_callback(void ** mutex, enum AVLockOp op) return NO; } + streamIndex = -1; for(i = 0; i < ic->nb_streams; i++) { c = ic->streams[i]->codec; if(c->codec_type == AVMEDIA_TYPE_AUDIO) { NSLog(@"audio codec found"); + streamIndex = i; break; } } + + if ( streamIndex < 0 ) { + NSLog(@"no audio codec found"); + return NO; + } avformat_find_stream_info(ic, NULL); @@ -143,7 +150,7 @@ int lockmgr_callback(void ** mutex, enum AVLockOp op) default: return NO; } - totalFrames = c->sample_rate * (ic->duration/1000000LL); + totalFrames = c->sample_rate * ((float)ic->duration/AV_TIME_BASE); frequency = c->sample_rate; seekable = YES; @@ -290,7 +297,9 @@ int lockmgr_callback(void ** mutex, enum AVLockOp op) - (long)seek:(long)frame { NSLog(@"frame: %ld", frame); - return 0; + AVRational time_base = ic->streams[streamIndex]->time_base; + av_seek_frame(ic, streamIndex, frame * time_base.den / time_base.num / frequency, 0); + return frame; }