0

I am reading a AVURLAsset and init the reader with the following call

AVAssetReaderOutput *assetReaderOutput =
[AVAssetReaderAudioMixOutput
 assetReaderAudioMixOutputWithAudioTracks:songAsset.tracks
 audioSettings: nil];

The songAsset (AVURLAsset) is initialized with a MPMediaItems URLAsset property.

I get a crash from this on certain assets.

[AVAssetReaderAudioMixOutput initWithAudioTracks:audioSettings:] tracks must all have media type AVMediaTypeAudio'

Why exactly is this if the MPMediaItem is an audio asset and plays in itunes?

some_id
  • 29,466
  • 62
  • 182
  • 304
  • Is this file available locally or is it an iTunes match song? If it's the latter, the file needs to be downloaded first. iTunes streams these files which is why it works fine there but not in your code. – BlueVoodoo Mar 13 '13 at 22:38
  • I added these files all locally. – some_id Mar 13 '13 at 22:43
  • I just saw it is .mov files. How can the AVMediaTypeAudio be checked? – some_id Mar 13 '13 at 22:48
  • 1
    Just do AVURLAsset* asset = [[AVURLAsset alloc]initWithURL:url options:nil]; if ([[asset tracksWithMediaType:AVMediaTypeAudio] count] == 0) NSLog(@"this file has no audio"); – BlueVoodoo Mar 13 '13 at 22:50

1 Answers1

0

Instead of songAsset.tracks, use [songAsset tracksWithMediaType:AVMediaTypeAudio] instead. Some assets have a video and audio track, such as iTunes music videos.

try this

NSArray <AVassetTrack *> *audioTracks = [songAsset tracksWithMediaType: AVMediaTypeAudio];
assetReaderOutput = [AVAssetReaderAudioMixOutput assetReaderAudioMixOutputWithAudioTracks: audioTracks
                                                                            audioSettings: nil];
Akhrameev
  • 325
  • 4
  • 12
Max
  • 1