C # winform: Play multimedia files [audiovideoplayback]

Source: Internet
Author: User

Preface

Keywords: C # Microsoft. DirectX. audiovideoplayback, C # player

Speechless.

 

Body

1. Support for playing multimedia files

". Avi", ". wmv", ". MpEG", ". mpg"

 

2. Preparation

The Microsoft. DirectX. audiovideoplayback namespace is included in the Framework. You need to install the Microsoft DirectX SDK separately. For convenience, we provide two required DLL files: microsoft.directx.rar.

    

Iii. Implementation

Create a winform project and reference the namespace: using Microsoft. DirectX. audiovideoplayback;

3.1 Initialization

Video movie;
Microsoft. DirectX. audiovideoplayback. Audio audio;

Path = path. tolower ();
If (path. startswith ("http: //") | path. startswith ("https ://"))
Movie = video. fromurl (New Uri (PATH), true );
Else
Movie = video. fromfile (PATH );

Audio = movie. Audio;

Code Description:

A) Note that the variables movie and audio are member variables of the class.

B). Video supports local/remote video file playback.

C). Do not paste the verification code about path here. Simply add it.

3.2 common methods and attributes

Play

Stop

Pause pause

Currentposition and duration work together to control the overall progress and current progress (position)

Audio. volume controls the sound size. Note the range

3.3 stop playing and release resources

Try
{
Movie. Stop ();
If (audio! = NULL)
Audio. Dispose ();
Audio = NULL;
If (movie! = NULL)
Movie. Dispose ();
Movie = NULL;
}
Catch
{
Try
{
Movie = NULL;
}
Catch {}
}

Code Description:

Call this code to release resources after playback.

 

4. Note

4.1 sound settings

The sound ranges from 0 to-10000. If your control is 0 to 100, use the formula: Value * 100-10000.

4.2 video object release

Before dispose, you can judge whether the video object is not null. You have found a lot of information before. If you directly dispose the video object, the code will not continue to be executed, or even try again.

4.3 Delegation after playback is completed

Movie. ending is not successful here. I also use a timer here to compare currentposition and duration in the timer. However, there is a problem here. It is possible that currentposition is not equal to duration after playing, therefore, we need to handle the problem and judge the value of the last currentposition record. If the two values are equal, it should also be over. Here, the timer is set to 1 second.

 

 

Conclusion

I officially went to work at the end of last month (September December). It is a new year gift for me. I like it very much. At last, I came to a company with at least regular welfare. I have many colleagues who can discuss it, take a good grasp of it and prepare to take root of the current development of mobile phones. It is estimated that some articles may be written after a while.

 

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.