[Reading Notes] iOS-stream audio and Pandora Radio, ios-pandora
Complexity is inevitable and will only increase over time. Therefore, when adding features, you must set aside time for restructuring and code simplification. Do not worry about performance before encountering problems. The iPhone is very strong and you may never encounter unexpected performance problems.
When transmitting audio to a device over the Internet, two transmission models can be used: Stream Transmission and download.
For stream transmission, the audio server transmits bytes over the network at the audio bit rate. For example, if the audio is encoded in 64 Kbits/s, it is foreseeable that this rate (64 kbit/s) will be used during stream transmission ). streaming audio is often used for continuous and uninterrupted music streams.
If audio transmission uses a download model, music is divided into discrete data blocks (for example, one song is transferred at a time ). the customer downloads and plays a data block as quickly as possible, and starts downloading the next data block only when the first data block is about to be downloaded.
Various models have their advantages and disadvantages. Streaming Transmission requires less client memory overhead (data is consumed once transmitted), and the customer's implementation complexity is lower (at the cost of higher server complexity ). However, in a program, stream transmission is more likely to damage audio due to network latency and packet loss. On the other hand, the downloaded audio content overhead is greater (because the audio segment may be quite large), and the client complexity is also greater. However, the downloaded audio is more immune to network damage, because the network bandwidth can be fully utilized rather than limited to a fixed amount.
To achieve this feature, you need to know how many bytes of the song has been played so far, and save this information when the application ends, in addition, when the application is started, a part of the songs will be downloaded to resume interruption from the offset position at the exit.
Reference: amazing iPhone cool development-seven first-line experts programming and design examples