Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hintForMimeType: method #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions Classes/AudioStreamer.m
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,50 @@ + (AudioFileTypeID)hintForFileExtension:(NSString *)fileExtension
return fileTypeHint;
}

//
// hintForMIMEType
//
// Make a more informed guess on the file type based on the MIME type
//
// Parameters:
// mimeType - the MIME type
//
// returns a file type hint that can be passed to the AudioFileStream
//
+ (AudioFileTypeID)hintForMIMEType:(NSString *)mimeType
{
AudioFileTypeID fileTypeHint = kAudioFileMP3Type;
if ([mimeType isEqual:@"audio/mpeg"])
{
fileTypeHint = kAudioFileMP3Type;
}
else if ([mimeType isEqual:@"audio/x-wav"])
{
fileTypeHint = kAudioFileWAVEType;
}
else if ([mimeType isEqual:@"audio/x-aiff"])
{
fileTypeHint = kAudioFileAIFFType;
}
else if ([mimeType isEqual:@"audio/x-m4a"])
{
fileTypeHint = kAudioFileM4AType;
}
else if ([mimeType isEqual:@"audio/mp4"])
{
fileTypeHint = kAudioFileMPEG4Type;
}
else if ([mimeType isEqual:@"audio/x-caf"])
{
fileTypeHint = kAudioFileCAFType;
}
else if ([mimeType isEqual:@"audio/aac"] || [mimeType isEqual:@"audio/aacp"])
{
fileTypeHint = kAudioFileAAC_ADTSType;
}
return fileTypeHint;
}

//
// openReadStream
//
Expand Down Expand Up @@ -1274,14 +1318,12 @@ - (void)handleReadFromStream:(CFReadStreamRef)aStream
if (!audioFileStream)
{
//
// Attempt to guess the file type from the URL. Reading the MIME type
// from the httpHeaders might be a better approach since lots of
// URL's don't have the right extension.
// Attempt to guess the file type from the httpHeaders MIME type value.
//
// If you have a fixed file-type, you may want to hardcode this.
//
AudioFileTypeID fileTypeHint =
[AudioStreamer hintForFileExtension:[[url path] pathExtension]];
[AudioStreamer hintForMIMEType:[httpHeaders objectForKey:@"Content-Type"]];

// create an audio file stream parser
err = AudioFileStreamOpen(self, MyPropertyListenerProc, MyPacketsProc,
Expand Down