I am using silverlight plugin for playing media files.
I am taking Play rate control for increase/decrease media play rate speed.
There is on pop up with progress bar which is shown when media element is in buffering mode.
This is code for checking media is buffering mode.
if(_myMediaElement.CurrentState == MediaElementState.Buffering)
{
//Show pop_up for with buffering progress bar
}
Issue : when I increase play rate using play rate slider control and than increase media position by reset media element with new time span position than media element goes buffering mode. but _myMediaElement.CurrentState is always showing playing mode. therefore unable to showing pop_up for with buffering progress bar.
Code for changing play rate
_myMediaElement.PlaybackRate = _playRateSliderControl.Value; // it can be 0.5, 1.0, 1.5
Code for increase media position
_myMediaElement.Position = new TimeSpan(0, 0, newPosition);
Any help is appreciate
Thanks
I have fixed it.
when I increase playrate from 1.0 than if media element is in buffering process that time I have assign
playrate = 1.0 and take in another variable of increase playrate value. and than when buffering is completed and media element player played the stream than reset playrate by increase value.
Related
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}"/>
I am working on a research project which needs precise timing/synchronize between the on screen display and a trigger from parallel port in Unity.
What I am trying to do is to flash the screen to white while sending a trigger to the parellel port at the same time (desired difference is within 10ms).
I mesured the screen flash with a photodiode to determine the exact time it turns white, and synchronize it with the trigger from parellel port. I always observed a delay of 40 - 70ms between the trigger and the flash (the flash arrived slower) which is my main problem.
What I have tried so far:
- Update the flash and send the trigger in the same frame (bigger delay)
- Update the flash -> WaitForEndOfFrame() -> send trigger (lower delay but still big). Below is a sample code:
IEnumerator UpdateParallelPort()
{
while (true)
{
yield return new WaitForEndOfFrame();
if (flashed == FlashState.ToWhite)
{
parallelPort.SendTrigger();
}
}
}
I also tested if the flash take multiple frames to be rendered by using ReadPixels to determine at what frame the screen turn white, but it was not the case, it was in the same frame when I issued the command. So I guess the delay comes from the time the buffer being sent to screen ? If that is the case, is there anyway to determine/synchronize the exact timing, or to minimize it ?
This is my first post in Stackoverflow, hope that I explained it clear enough. Thank you in advance for your help!
which needs precise timing
I have bad news, completely forget it.
Unity is a game engine through-and-through.
The whole entire raison d'etre, the most fundamental aspects of it, is that it lets you render mesh of dinosaurs etc, with "total compromise" of granular time, and reasonable overall perceptive time.
Unfortunately, you literally could not choose a worse milieu for the project! Sorry! :O
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.
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.
in my form, I have a small media player, it's pretty basic, it has the basic functionalists
nest, previous, play, stop, volume increasing and a track bar.
I was able to seek the song by dragging the track bar via this code::
(Assuming that the maximum value of the track bar is the total number of seconds of the sound file)
private void SeekBar_Scroll(object sender, EventArgs e)
{
Player.Position = TimeSpan.FromSeconds(SeekBar.Value);
}
But I wasn't able to make the bar move forward by itself when the music is playing ..
I came up with this idea:
let's say we have a 90 secs duration song.
now the track bar maximum value is 100
so:
100 --> 90
1 --> X
X = 0.9 sec
this is the interval between the ticks of the bar and the value that the track bar value should be increased in every tick. Here is my code:
while (SeekBar.Value < 100)
{
System.Windows.Duration duration = Player.NaturalDuration;
SeekBar.Value += duration.TimeSpan.Seconds / 100;
Thread.Sleep(duration.TimeSpan.Seconds * 10);
}
Now I think this should be run in a separate thread right ?
but the problem, when i do that, I get the annoying message of saying that the TrackBar is being used in a thread other than the thread it was created on ..
how can i get around that ?
I wanted to put this code in both the MouseLeave and MouseEnter events, but it's pointless, cuz it will be on the same thread and the app will freeze..
How can i make the bar move by it self ?
You should create a WinForms Timer with an interval or 1,000 milliseconds, and update the trackbar in its Tick event.
It sounds like you have the hardest part done (mapping the length of the scroll bar to the length of the audio file). The rest is easy.
You can tackle this with a Timer. Set the interval to some value (such as 1000ms or maybe 500ms, and in Tick, update the scrollbar (call SeekBar_Scroll). For the exact interval, test and see what looks the most natural.
A while-loop will probably eat unnecessary CPU, not to mention lock up the rest of your application.
To get around the control updating, you need to check this SO question. You need to check control.InvokeRequired and set it via the Invoke method if that's the case.