I'm trying to be able to affect SpeedRatio on a MediaElement whilst having the media play in a continous loop.
This is possible through code behind; I can reset the position of the media once it has ended, but that creates a seam in the playback.
For seamless playback, I use a MediaTimeline, but when I use I media timeline, I can't change the SpeedRatio.
Has anyone got a different approach to looping playback in a mediaElement, or handling SpeedRatio?
UPDATE:
If I stop the timeline, change the timeline's SpeedRatio, I can produce the result I'm looking for. The only remaining problem is getting the timeline to start from the same position that it was stopped at. Pausing the timeline does not allow for the SpeedRatio to be changed.
I still welcome any alternatives.
My MediaUriElement in my open-source project has a "Loop" property that can provide seemless looping. Get it from the source because it's the newest.
The only solution I've found for this is to use XNA to control audio. It's got a lot more responsiveness.
Related
So here's my setup:
Camera images coming in at 1920x1080 # 25 FPS
Writing image data to WriteableBitmap on UI thread (simple copy, no processing)
Two Image controls in two different windows on two different monitors has their Source property set to the WriteableBitmap
Some generic UI stuff goes over the camera images
This works great, uses about 4% CPU on an old laptop (8 logical processors). The video is as smooth as can be. However, my UI has some animations (stuff moving around). When the camera display is running, those animations gets choppy.
Right now, the camera image is in Gray8 format, so it will be converted (I guess when calling WritePixels?). I also tried forcing one of the animations to 25 FPS too, no change.
Where should I start to resolve this? Is the issue that I'm locking the bitmap for too long, or is there something else going on? From what I can see locking the bitmap will cause the render thread to block, so moving that to another thread seems pointless. And it does feel like that somewhat defeats the purpose of WriteableBitmap.
This is always going to be tricky because you're capturing at 25FPS whilst WPF tries to update at 60. It's difficult to offer any meaninful advice without seeing a testable project but I'd probably start by doing the updates in a CompositionTarget.Rendering handler.
I want the animation to be done based on the audio that will be played?Is this possible to do?
Basically I have a pulse animation that need to be done based on the audio?How can I do this.Hope got my idea.
This is possible. Detailed implementation of audio capture and processing is available in AudioGraph (https://github.com/tkzic/audiograph). The same demo contains a very basic example of animating based on audio (just displaying a level meter using progress bar controls).
For better animations, you can use OpenGL ES together with the code above. I have done this in one of my projects.
I'm trying to make a text reader for my WP7.
I'm using a mediaElement in my reader.
at first every time the app read something, the MediaPlayer stopped, as I later discovered that is how it is designed.
Then I tried to try and trick the system, by using
mediaElement1.Stop();
mediaElement1.SetSource(isolatedStorageFileStream);
FrameworkDispatcher.Update();
MediaPlayer.Pause();
mediaElement1.Play();
if (mpState != MediaState.Stopped)
{ MediaPlayer.Resume(); }
now comes the wierd part,
when I use the reader once, it reads and the music seems to run without any pause, as I wanted, but when I use the reader for the second time, the MediaPlayer stops to play.
when I've added some breakpoints, I've noticed that after the first read, the MediaPlayer.state is paused, but it still plays.
I have some kind of a media player in my app, so I have some listBoxes that are filters, I want to read to selected filer (artist, album, etc.). so basically using the reader happens when selected item is changed. I'm using both MediaPlayer and MediaElement because if i won't pause the mediaPlayer, it will stop, and I will lose the position of the playing song. and because I want the reader to play gapless I'm using a mediaElement.
I'm lost...
Try looking at this (Music + Videos Hub Sample) http://go.microsoft.com/fwlink/?LinkID=203588 which I think you already use (using the media libraries on the phone), but try combining it with this (Silverlight Sound Sample) http://go.microsoft.com/fwlink/?LinkID=207868, which shows how to use XNA to play sounds in parallel.
If you carefully mix & match these 2 examples, you can achieve what you want, I’ve just tried it myself. Simply copied all that’s needed from example 1 into example 2, and it works just fine: the background music plays, and the birds happily chirp without harming one another.
Let me know if you have problems with it.
BTW - over here: http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx you have many working examples, for many different things. I took both examples above from this link.
Eyal
I'm using VB.net 2010 and WPF 4. I need to have a smooth transition between two videos played on the mediaelement. I absolutely cannot use anything that requires me to use a winhost in the WPF window, as that will make my project impossible (since the video is full screen, and the controls are over the video)
Basically, I need for the video to play through, and then smoothly go to another video specified in code behind. I cannot splice the two videos together - they must be separate.
How do I have the videos transition smoothly, with no "blink"?
I'm guessing without testing here. You're probably going to need some CPU cores and a good video card.
If you have the memory, use two MediaElements.
Queue up both videos, one on each element.
Set the opacity of the second one to completely transparent. They're UIElements so this should work...
Use timers of some kind keyed from the start of playback on the first one so that you get an event a couple of seconds before playback ends.
With that event delegate, start the video in the second MediaElement, animate the first one's opacity to zero while simultaneously animating the second one to fully opaque.
If you need to do it again, set up the timer again and make sure your delegate animates things the other way.
I am working in WPF, using a Media Element and a WPF TeeChart (by Steema). Both of these are visible and updating at the same time - whilst the video is playing, the graph will update at regular intervals to show data relevant to the current location in the video.
The problem is that the TeeChart takes a long time to update, which blocks the video thus causing the playback to become jerky.
I have experimented a little with multithreading to try to find a solution for this, but so far have had no luck. I cannot dictate when either the video or the chart updates, in fact I suspect WPF works in such a way that any WPF elements are always drawn together.
Can anybody think of anything I can do to resolve this issue? At the moment all I can think of is replacing one or both of these elements with a Win32 equivalent and hosting it appropriately, but for numerous reasons I am leaving this as a last resort.
Just in case you still haven't solved that issue or for future reference, you can optimize TeeChart's performance as described in the "Real-time Charting" article here:
http://www.teechart.net/reference/articles/index.php
This is a TeeChart VCL article but most of it also applies to TeeChart for .NET
Also notice that TeeChart for .NET is not thread safe. You need to give enough time to the chart to paint itself. You can either do this using a a sleep call so that the chart painting finishes in the given time or use asynchronous painting technique with AutoRepaint property, for example:
tChart1.AutoRepaint = false;
Random r = new Random();
for(int i = 0; i <500; i++)
{
tChart1[0].Add (i,r.Next(800),Color.Blue);
}
tChart1.AutoRepaint = true;
tChart1.Refresh();