Use ssme in silverlight3 to reproduce the big buck bunny player

Source: Internet
Author: User
In the previous lecture (using smoothstreamingmediaelement in Silverlight to create an smooth streaming player), I introduced in detail how to use the smoothstreamingmediaelement (ssme) Control in silverlight3 to compile a player that supports smooth streaming video streams, as you can see, the player is very simple and has no bright appearance, and its functions are very simple. Of course, you can add some control elements on the interface to enrich the player's functions, for example, forward, backward, left and right channels, full screen, etc. In fact, all these mediaelement controls are supported. You only need to write simple logic to control them, it is also relatively simple. The focus of this article is not on how to add these features, but on how to implement the floating panel for real-time tracking of the playback status of the smooth streaming video stream in the big buck bunny player. The following figure shows the effect to be imitated:

You can see that the player has three floating panels, showing the frame rate and bit rate during the current video playback and the bit rate during custom video playback. We have understood the principle of smooth streaming technology. It can dynamically transmit videos of different quality based on the bandwidth requested by the client. When the network status is good, the quality of the videos played is high, when the network status is poor, the quality of the video to be played is relatively poor, thus ensuring the smoothness of video playback. On the official website, you will find information about the smooth streaming technology. You can also find some content about the ssme control on Microsoft's msdn, before you start, you need to download the smooth streaming SDK. These steps are the first twoArticleHas been described in detail, interested readers can refer.

Http://www.cnblogs.com/jaxu/archive/2010/01/08/1642143.html

Http://www.cnblogs.com/jaxu/archive/2010/01/21/1653314.html

The content in the SDK is only suitable for demonstration and does not contain the sample player.Source codeIf you want to refactor the player, you can only do it yourself, but in fact we have some shortcuts. Do you still remember the reflector decompilation tool I introduced to you in the previous article? In the silverlightbrowser plug-in, we can decompile the demo player in the SDK to see how it implements the three floating panels.

After decompilationCodeAfter research, we found that the tracking panel of Frame Rate and bit rate is actually a Silverlight custom control, so that we only need to introduce the corresponding DLL files in our project, we can directly use them. As for the bit rate setting panel, there are actually two silder controls. The value_changed event is used to control the playback of smooth streaming. The following is the code I decompiled and sorted out. You can download it and study it. When using xap, refer to the example in SKD.

Smoothstreamingtest.rar

There is a problem here, that is, the mainplayer in the Code is a custom control, and from the perspective of decompilation, restructuring is basically impossible (the structure is complicated, there are many classes, refactoring is too costly ). In fact, ssme is used in this custom control. In this case, we should replace it with ssme directly, and then slightly change the code. The whole code should be very simple, because it is based on the results of decompilation, you just need to sort out some useful code. I will give a brief explanation here.

1. There are some required styles in the mainpage. XAML and App. XAML files to be added to the corresponding files in your project.

2. The layout code for the three panels in the mainpage. XAML file needs to be added to the corresponding place in your project.

3. The background code can be directly provided by me. Includes the definition of private member variables, updatecontrolreferences method, findvisualelementfrom method, limitmaxbitrateslider_valuechanged event, ontimercompleted event, and supplement to smoothplayer_mediaopened event.

Basically, the other parts are used to explain the usage of ssme in the previous article, and no changes have been made.ProgramFirst, an animation is defined to control the path changes in the Frame Rate Tracking panel and Bit Rate Tracking panel, after the video is successfully opened, the relevant parameters of the three panels are initialized to display the content in the panel, and then the animation is executed, after the animation is executed, update the Panel value based on the current playback status of ssme and modify the path in the panel, and then re-execute the animation. This is the basic process. The following is my code.

Smoothstreamingplayer.rar

The following items are successfully run:

Of course, you can add a tooglebutton to control the display or hide Panel. This allows you to directly control the visibility attribute of the overlayspacinggrid control.

One problem you may need to pay attention to is that when you find that you are playing a video, the bit rate tracking information is always shown at the bottom of the file, the progress bar in the now downloading bite rate panel is always at the leftmost position, in this case, you may need to review the size of your ssme and the size of your converted smooth streaming video file, you can manually adjust the video file size when converting the video (the size is consistent with the size of your ssme control), and then try again. This is a problem I encountered during the application process. One of the video players I wrote at the time was embedded in a Silverlight plug-in, with a small footprint, as a result, the above problem occurs. We can see that the video quality has obviously changed, but the bit rate tracking information remains unchanged for a long time, at first, I thought it was a problem with the Code itself. Then I accidentally changed the size of the video source file to solve it. Write it here to remind everyone. Of course, you don't need to adjust the size if you haven't encountered this problem during usage.

The smooth streaming technology is still in the exploratory stage. The actual application examples are basically from the big buck bunny player on the official website, at present, we can successfully build an smooth streaming server on our own machine by using iis7, and then quickly create a smooth streaming video player in silverlight3 through ssme. In this article, by studying the examples provided on the official website, we also learned how to add playback tracking information to ssme.

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.