track bar in media file using DirectShow lib in c# - c#

i want to use a track bar in a window form which opens a media file as the video or audio plays i want to move the slider of the track bar accordingly . I had set all the properties of the track bar tool like maximun,minimun, tickfreguency small and large change accordingly.
using mediaposition i collect the currentPosition of the media and total duration using get_duration() method and sets the trackbar value to the current position but the problem is as the media is running the slider of the bar is not moving . i know i am missing something in the code .

Make sure you actually update that information in LOOP. So it would be updated, for example, in timer. Every 1 second.
You can also check what values you get from those two calls(get_duration and get_position) using debugger.

Related

Controlling Sounds in audio in multiple forms

I want to play a playlist in the resources folder for a windows forms project I'm working on (wav or mp3). The application will be completely offline. (actually a game project)
What I want to do is this:
I need to be able to stop or convert a music that I created in one form to another sound file, depending on the situation.
In this case, I couldn't figure out how to write a code block. There are many examples that describe how we can pause and start the music on single form, but I have not come across an example that covers the whole project and can be intervened from different forms.
I'm not sure if I explained exactly what I wanted to ask, but I can give an example as follows. Let's say I created 3 forms.
1st form and 2nd form game menus.
In these menus, the same music should continue to play.
But when I reach the 3rd form, this music should be cut and replaced with in-game music.
What I want to ask is: How can I control the music I created in form 1, in form 2 or form 3?
The reason I don't use the soundplayer class is because I have to play multiple sounds at once.
i.e., somehow I need to make the music player "static" so that I can control it from all forms, but I couldn't find the way around it.
var importer = new RawSourceWaveStream(Properties.Resources.sound, new WaveFormat());
var soundFx = new WaveOut();
soundFx.Init(importer);
soundFx.Play();
For example, in this way, I start playing the music in the form1. I need to give the command to change this music in the form3, but somehow I cannot reach the "soundfx" object that I defined there because I cannot make this process static.
I think that your intuition is valid. It is probably not the best way, but I inffer that it is a way that you would manage to do.
Have a public static class, that holds a private (or public) instance of you sound player. Have public static methods of the different things that you want to do with the audio player.
Control that class from all forms.
Since this is your intuition. I am curious of what have you so far in this way?
Anyhow, I have a few questions.
When you say "convert" the music, what do you mean?
What do you mean that you couldnt find a way around it?
Can you add some code of how you are controlling the sounds? With some code, people will be able to better support you.
It is recommended that you use MediaPlayer. From your description, MediaPlayer can better meet your needs. Compared with SoundPlayer, MediaPlayer has the following characteristics:
Multiple sounds can be played at the same time (create multiple MediaPlayer objects);
You can adjust the volume (Volume property);
You can use Play, Pause, Stop and other methods to control;
You can set the IsMuted property to True to achieve mute;
You can use the Balance property to adjust the balance of the left and right speakers;
The speed of audio playback can be controlled through the SpeedRatio property;
The length of the audio can be obtained through the NaturalDuration property, and the current playback progress can be obtained through the Position property;
Seek can be performed through the Position property;
Use MediaPlayer to play audio files as follows:
MediaPlayer player = new MediaPlayer();
player.Open(new Uri("BLOW.WAV", UriKind.Relative));
player. Play();
A MediaPlayer object can only play one file at a time. And the file is played asynchronously, you can also call Close to release the file.
For details, please refer to https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.mediaplayer?view=windowsdesktop-7.0
When using it in VS, you need to perform the following steps first:
This way you can find MediaPlayer in the toolbar.
If you still have any questions please speak up.

How to refresh animation state in unity to know what animation is playing

Ok so, I did this:
print(Anim.GetCurrentAnimatorStateInfo(0).shortNameHash);
When I play an animation like so
Anim.Play("AnimationName");
The value printed changes and then stays the same and doesn't change back to the default animation.
I also tried with the following:
if (Anim.GetCurrentAnimatorStateInfo(0).IsName("FireAnimation"))
I want to be able to get a constant update on the current animation that is playing. If you have any method that doesn't involve using a clock please do help.
I realized the best way to do this is to use the animation controller and change varialbes using SetBool(); and SetFloat(); etc.

UWP Application with video playback

How can I get the time of video playback in UWP C# Application?
I'm using Media Element and I have video playback in my app after I choose it from the file. I can pause it and start it again, but I don't know how can I get the real time of this video, when it's playing.
For retrieve current position of duration look at the MediaElement.Position property.
The amount of time since the beginning of the media. The default is a TimeSpan with value 0:0:0
If you want to know the playback duration you can use MediaElement.NaturalDuration property:
The natural duration of the media. The default value is a Duration structure that evaluates as Automatic, which is the value held if you query this property before MediaOpened.
You can bind on Position property of MediaLement like this:
<MediaElement x:Name="MediaElement1"/>
<TextBlock Text="{Binding Position, ElementName=MediaElement1}"/>

WPF / C#: async load/buffer next movie clip

I need a main 'home' video (full screen HD) running in a loop, and then at some point (say the user presses a key) another short movie plays (one of twelve selected at random), and then back to the home movie loop.
I'm using the mediaElement in WPF from my C# code - Is there a way to load the next movie into memory so that it's ready to play instantly? It currently takes about a second or so...
(I'm actually using two media elements with the triggered movie on top - I was doing a cross fade but have taken that out now until I can buffer the next clip. Not sure if this is the best way of doing this, any ideas? Many Thanks.
I figured out a way in case anyone is interested.
You can just specify a bunch of mediaElements on top of each other (can have different z index but not essential). Then did
video.Opacity = 0.0;
video.Play();
video.Pause();
for all of them, then when you want to play one you just set the opacity to 1 and play it and it'll play instantly.
Don't know if that's the best way, but works well. Now going to implement a cross fade to finish up. Happy days.

Can I set the frames per second of a MediaElement in C#?

I have a media element that normally plays videos fine, but some videos with high framerates(120) play at the wrong speed. I assume it is something to do with the video not having the right information in the header, and am looking into setting it manually.
Is there a good way to set the Frames Per Second of a MediaElement?
Because there are no methods or variables in the Media Element to get or set the frame rate, the only viable solution I found was to have a text area that set a frame rate multiplier. This multiplier can then be applied to the SpeedRatio of the Media Element, as well as anywhere else where events dependent on the video time are determined.

Categories

Resources