Multimedia streaming media, streaming media and multimedia

Source: Internet
Author: User

Multimedia streaming media, streaming media and multimedia

Multimedia technology is becoming more and more widely used, especially when you listen to music and watch videos. If we want to complete an example of loading resources from the network and playing the video, we need to use multimedia, multimedia Apple has its own features but is not very powerful. If more powerful features are needed, we need to use a third party. Now we use the multi-media library provided by Douban for a simple playback instance.

1. First, we need to import the Library to the database. First, we need to download the response class library from the official website and introduce it to the project.

 

2. For Class Libraries, we also need to introduce the corresponding support framework, as shown in figure

 

3. After completing the above work, we can build the interface. We will use storyboard to build a simple interface and link the corresponding output port,

 

@property (weak, nonatomic) IBOutlet UILabel *spedd;@property (weak, nonatomic) IBOutlet UILabel *receive;@property (weak, nonatomic) IBOutlet UILabel *total;

4. Now we can start programming. first introduce the header file.

# Import "DOUAudioStreamer. h "/** Douban streaming media object */@ property (nonatomic, strong) DOUAudioStreamer * stream; // it is found that a parameter is required to initialize the stream object, and the parameter is of the id type, and comply with the DOUAudioFile protocol, so we encapsulate a class JRAudioFile, and there is an attribute in it that is an audio link.

Then we can initialize the stream object.

// Initialize the file JRAudioFile * file = [[JRAudioFile alloc] init]; file. audioFileURL = [NSURL URLWithString: @ "http: // localhost/ghsy.mp3"]; // initialize the stream self. stream = [DOUAudioStreamer streamerWithAudioFile: file]; // start playing [self. stream play];

5. During audio playback, we need to monitor the download progress. In this case, we need to monitor the download progress through KVO, as shown below:

[Self. stream addObserver: self forKeyPath: @ "bufferingRatio" options: Adjust context: nil]; # pragma mark-observed callback method-(void) observeValueForKeyPath :( NSString *) keyPath ofObject :( id) object change :( NSDictionary *) change context :( void *) context {// here we need to divide by 1000 to convert the unit, not 1024 CGFloat expectedLength = self. stream. expectedLength/1000.0/1000.0; CGFloat receivedLength = self. stream. receivedLength/1000.0/1000.0; CGFloat downloadSpeed = self. stream. downloadSpeed/1000.0/1000.0; // return to the master thread dispatch_sync (dispatch_get_main_queue (), ^ {self. spedd. text = [NSString stringWithFormat: @ "download speed: % gKB/S", downloadSpeed]; self. total. text = [NSString stringWithFormat: @ "file size: % gM", expectedLength]; self. receive. text = [NSString stringWithFormat: @ "accepted: % gM", receivedLength] ;}); NSLog (@ "%. 2f, %. 2f, %. 2f ", expectedLength, receivedLength, downloadSpeed );}

Then a simple network audio is played.

 

For questions or technical exchanges, please join the official QQ group: (452379712)

 

Author: Jerry Education
Source: http://www.cnblogs.com/jerehedu/
The copyright of this article belongs to Yantai Jerry Education Technology Co., Ltd. and the blog Park. You are welcome to repost it. However, you must keep this statement without the author's consent and provide the original article connection on the article page, otherwise, you are entitled to pursue legal liability.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.