Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a wav file automatically in IE

Status
Not open for further replies.

whosrdaddy

Vendor
Mar 11, 2003
4,231
BE
I have this in my Controller:

Code:
public FilePathResult GetWaveFile(string id)
        {
            var provider = new MessageFilesProvider();
            return File(provider.GetWaveFile(id), "audio/x-wav");
        }

my provider looks like this:

Code:
public interface IMessageFilesProvider
    {
        IEnumerable<string> Files();
        string GetWaveFile(string fileName);
    }

    public class MessageFilesProvider : IMessageFilesProvider
    {
        private readonly IMessagePathProvider pathProvider;
        public MessageFilesProvider(IMessagePathProvider pathProvider)
        {
            this.pathProvider = pathProvider;
        }

        public MessageFilesProvider() : this(ServiceLocator.Current.GetInstance<IMessagePathProvider>()) { }

        public IEnumerable<string> Files()
        {
            var path = pathProvider.MessagePath(MessageType.RecordedMessages);
            return Directory.GetFiles(path, "*.wav", SearchOption.TopDirectoryOnly); 
        }

        public string GetWaveFile(string fileName)
        {
            var path = pathProvider.MessagePath(MessageType.ActiveMessages);
            return Path.Combine(path, fileName);
        }
    }

when I test this in FireFox (ie /mysite/GetWaveFile/test.wav), Mediaplayer opens automatically and plays test.wav.
In IE however, Media player is opened, Mediaplayer says "changing media" and the bombs out with the error "Windows Media player cannot play the file".

I suspect that FF is downloading the file and the opens it with WMP and that IE is doing something else.

if I change the line
return File(provider.GetWaveFile(id), "audio/x-wav");
to
return File(provider.GetWaveFile(id), "audio/x-wav", id);
I get a download dialog, which is expected since it adds the content-disposition header. This works in FF and IE, but I want to be able to play the wave file immediately.

Any suggestions?

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
you may need to adjust the headers of response.
Code:
response.AppendHeader("Content-Disposition", "attachment;");
there may be other examples on the web. the problem how asp.net delivers the content. whether it's webforms or MVC is indifferent.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Jason,

response.AppendHeader("Content-Disposition", "attachment;");

this is exactly what the third paramater of Controller.File does (downloadFileName). It effectivly forces the save dialog (and I don't want that)

Mark,

I am aware of that, I just find it illogical that FF can serve the file correctly to WMP and not IE

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
if you don't want the save dailog use
Code:
response.AppendHeader("Content-Disposition", "inline;filename=whatever_you_want.wmv");

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
still looking for a solution for this problem.
Jason the correct header information is added by the FilePathResult. I did some procmon tracing and it seems that IE downloads the file with .dat extension and that is the reason why WMP doesn't want to play the file. FF downloads the file with it's correct extension and no problem there.

I have a temporary fix in place but if someone has a good solution ,please let me know.

temp fix:

Code:
// show download dialog on IE due to IE not naming the file correctly
 if (Request.UserAgent.IndexOf("MSIE", StringComparison.OrdinalIgnoreCase) > 0)
   return File(provider.GetWaveFile(filename), "audio/x-wav", id);
 return File(provider.GetWaveFile(filename), "audio/x-wav");

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top