Answered by:
MP3 Files inconsistently downloading on iPhone

Question
-
User2095086431 posted
So I have been trying to figure an issue for a while and I am running out of ideas. So here is the scenario, I have a mobile friendly website that allows users to stream MP3 files. It works perfectly fine on desktop browsers. However, when I test out on my iPhone (iOS5 on iPhone 4) it is hit or miss. At times the file will stream fine at times I get the following error: "The operation could not be completed". Not sure why it happens. But only thing I have noticed it happens on files larger than 5MB. I have tried making sure that the executionTimeout and maxRequestLength values are very high in the web.config file. I have been testing one large file of about 7MB and sometimes it will stream, sometimes it will not stream. Very inconsistent. Cannot for the life of me figure out why. Anyone encounter this issue? What would be the best workaround? The following is my streaming code(note it is copying the files from a local remote server). Thanks in advance!
'Create a stream for the file Dim stream As Stream = Nothing 'This controls how many bytes to read at a time and send to the client Dim bytesToRead As Integer = 10000 ' Buffer to read bytes in chunk size specified above Dim buffer As Byte() = New [Byte](bytesToRead - 1) {} ' The number of bytes read Try 'Create a WebRequest to get the file Dim fileReq As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://127.0.0.1/mp3s/file.mp3"), HttpWebRequest) 'Create a response for this request Dim fileResp As HttpWebResponse = DirectCast(fileReq.GetResponse(), HttpWebResponse) If fileReq.ContentLength > 0 Then fileResp.ContentLength = fileReq.ContentLength End If 'Get the Stream returned from the response stream = fileResp.GetResponseStream() ' prepare the response to the client. resp is the client Response Dim resp = HttpContext.Current.Response 'Indicate the type of data being sent resp.ContentType = "audio/mpeg3" 'Name the file resp.AddHeader("Content-Disposition", "attachment; filename=""" & filename & """") resp.AddHeader("Content-Length", fileResp.ContentLength.ToString()) Dim length As Integer Do ' Verify that the client is connected. If resp.IsClientConnected Then ' Read data into the buffer. length = stream.Read(buffer, 0, bytesToRead) ' and write it out to the response's output stream resp.OutputStream.Write(buffer, 0, length) ' Flush the data resp.Flush() 'Clear the buffer buffer = New [Byte](bytesToRead - 1) {} Else ' cancel the download if client has disconnected length = -1 End If 'Repeat until no data is read Loop While length > 0 Finally If stream IsNot Nothing Then 'Close the input stream stream.Close() End If End Try
Tuesday, October 16, 2012 1:54 PM
Answers
-
User1943143334 posted
Hi,
Yeah! May be byte by byte writing is not supported in the iPhone web browser! If the writing slows down, then in that scenario, it is throwing "Operation timeout"!
Instead, try providing the physical path location itself, so that it will be streamed automatically, based on the speed!
Hope it helps u...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, October 18, 2012 7:33 AM
All replies
-
User1943143334 posted
Hi,
Basically, It's also depends on the network bandwidth! Moreover, it's not recommended to use large files.
Did you tried using any Audio/Video streaming server - http://www.iis.net/learn/media/on-demand-smooth-streaming/getting-started-with-iis-smooth-streaming
Hope it helps u...
Wednesday, October 17, 2012 7:41 AM -
User2095086431 posted
Thanks Roopesh for the reply. Here is the weird thing, when I try to download large MP3 files from the actual physical location, (without using the ASP,NET code) it works perfectly fine all the time. The issue only comes up when I use the code I posted earlier. So was wondering if iPhone's Safari browser has some issue with the ASP.NET code. A security feature maybe? Would love to know what is wrong with the code.
Wednesday, October 17, 2012 6:23 PM -
User1943143334 posted
Hi,
Yeah! May be byte by byte writing is not supported in the iPhone web browser! If the writing slows down, then in that scenario, it is throwing "Operation timeout"!
Instead, try providing the physical path location itself, so that it will be streamed automatically, based on the speed!
Hope it helps u...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, October 18, 2012 7:33 AM -
User1073503637 posted
But how the hell to play audio on iphone safari if I want to generate it at the moment of user tap?
I can not predownload it because safari only allows playing as a result of user tap, and if I return a file as byte[] there is this nasty message sometimes "the operation could not be completed"
stupid iphone
Edit: this shit even happens with google translator audio playback http://imgur.com/36FOBR2
god I hate apple
Tuesday, May 14, 2013 12:13 AM -
User1943143334 posted
Hi,
In that case, create an audio file in the server and refer that in HTML 5 Audio tag!
Hope it helps u...
Wednesday, May 15, 2013 12:05 PM -
User1073503637 posted
No
iphone plays audio only as a result of user's tap, I can not generate file and in ajax success event use play()
Conclusion: when user taps the button the file should be there already or streamed to the url
Wednesday, May 15, 2013 12:12 PM -
User1943143334 posted
Hi,
If i understand your question correctly, then you may be looking for this -
For Audio Streaming, you need to setup the IIS server - http://www.iis.net/learn/media/on-demand-smooth-streaming/getting-started-with-iis-smooth-streaming
Hope it helps u...
Sunday, May 19, 2013 7:34 AM -
User1073503637 posted
"The on-demand Smooth Stream opens in the web browser, using the Silverlight browser plug-in for Smooth Streaming."
you are joking, right?
As of 26 August 2011, 0.3% sites are using Silverlight,<sup id="cite_ref-22" class="reference">[*]</sup>
And we are talking about iPhones here not even PC
Sunday, May 19, 2013 9:33 PM -
User1943143334 posted
Hi,
Yeah, i understand. Unfortunately, as i explained in my earlier post, when we write the data to the client(may be mobile browser), it also depends on the bandwidth. Moreover, in your case it's Audio file, which you wish to play, while streaming!
This is possible, if you have an Audio file already in place!
Moreover, seems like Smooth Streaming is available for iPhones as well - http://www.iis.net/learn/media/smooth-streaming/adaptive-streaming-comparison
Hope it helps u...
Monday, May 20, 2013 2:27 AM