Modify the duration of a video in Windows Media Player - c#

for a new project, I used the Windows Media Player component. It should play a Livestream and this works fine for me, but after 10s the stream loads again and begins at 0 seconds (just like a 10s video clip).
There are two solutions I can see, but I don't know a way for them. The code itself is pretty simple.
private void tbutton_Click(object sender, EventArgs e)
{
tvplayer.currentPlaylist.name = "TV-Stream";
tvplayer.URL = (stream-url);
}
The first would be to "let the player know" that the video source is a stream and not a video, but I don't know how I should do that.
The second solution would be to modify the duration of the "video", the Media Player plays to... maybe two hours or 24 hours. I know this is somehow possible as I read about it in the Metafile Elements Reference (https://msdn.microsoft.com/de-de/library/windows/desktop/dd564668(v=vs.85).aspx), anyway, I don't see how.
Can someone give me a hint how I could do that?
I tried both HLS and HDS versions of the livestream, there is no difference. The problem is the same. The stream itself has a H.264 MP4-format.
I guess the problem is that the livestream is loaded in 10s-segments.

Related

(c#) Playing and controlling multiple sound files using DirectShow

I have very little experience with DirectShow, so far I have managed paly a .wav file over a particular output device while being able to control its volume and get/set its track-position. Basically I’m able to create a very simple sound player application.
Here is the code I’m currently using:
//select an output device
DsDevice[] devices = DsDevice.GetDevicesOfCat(FilterCategory.AudioRendererCategory
DsDevice device = (DsDevice)devices[xxx];
//define a source
Guid iid = typeof(IBaseFilter).GUID;
object source = null;
device.Mon.BindToObject(null, null, ref iid, out source);
//build a basic graph to play the sound
IGraphBuilder player_gra = (IGraphBuilder)new FilterGraph();
player_gra.AddFilter((IBaseFilter)source, "Audio Render");
player_gra.RenderFile(#"test.wav", "");
//start the sound
(player_gra as IMediaControl).Run();
//control the volume
(player_gra as IBasicAudio).put_Volume(volume);
//get/set position on the track
(player_gra as IMediaPosition).get_Duration(out out1);//how long the track is
(player_gra as IMediaPosition).get_CurrentPosition(out out2);
(player_gra as IMediaPosition).put_CurrentPosition(yyy);
What I would like to do now is to play several .wav files simultaneously while being able to control the volume and track-position of each file at runtime.
My first attempt was to create several IGraphBuilder instances and run them at the same time but it seem that only one can play at the same time while the others wait until the currently playing one is terminated via:
Marshal.ReleaseComObject(player_gra);
My second attempt was to give the IGraphBuilder several Files to render before starting it.
…
player_gra.RenderFile(#"testA.wav", "");
player_gra.RenderFile(#"testB.wav", "");
player_gra.RenderFile(#"testC.wav", "");
…
This way the files are played simultaneously but I see no way to control the volume of each individual sound, much less its position on the audio track.
Thank you in advance ;-)
In these lines
DsDevice[] devices = DsDevice.GetDevicesOfCat(FilterCategory.AudioRendererCategory);
DsDevice device = (DsDevice)devices[0];
you enumerate audio output devices and pick the first "random" device which appears to be Default WaveOut Device or one of its instances.
It has a legacy behavior that only one active instance is actually sending data to playback. There is no fundamental limitation in the system to prevent from simultaneous plyback, it is just legacy behavior.
That is, you have both graph playing but audio from the second is muted.
Audio mixing is disabled in the waveOut Audio Renderer, so if you need to mix multiple audio streams during playback, use the DirectSound renderer.
If you use Default DirectSound Device instead (which you can quickly pick up by using different index in device[NNN] in code) you'll hear what you expect to hear.
DirectShow.NET does the enumeration somehow confusingly, Default DirectSound Device normally has highest merit and is listed first and you seem to be given devices in different order.

Launching a stream in VLC from C# program

Maybe it is just late, but I ran into a dead end, hoping someone can help me out.
I have a very simple program which is supposed to work like this: The user can see a list of available streams. The user picks a stream to watch. After picking a stream I then want to launch VLC media player for them and play it.
I have everything in order except from one last thing - I don't know how to make the player play the stream. I assumed it would just be something like this:
System.Diagnostics.Process.Start(pathVLC, streams[choice]);
where
PathVLC is the path to the users player, for example C:\Programs\VLC\vlc.exe
streams is an array of strings, all on the form "http://somerandomstream.m3u8"
choice is the stream the user wanted to see.
While VLC opens successfully, nothing else happens, and I am completely lost on how to actually tell VLC to play the stream. What am I missing?
Edit: Looking at Vaughan Hilts answer I figured it out!
System.Diagnostics.Process VLC = new System.Diagnostics.Process();
VLC.StartInfo.FileName = pathVLC;
VLC.StartInfo.Arguments = "-vvv " + streams[choice];
VLC.Start();
You'll be required to start it up from the command line like so:
vlc -vvv http://www.example.org/your_file.mpg
This means you will need to pass in the -vvv flags as well in your array to succesfully start the stream.
I would start from inspecting supported command-line arguments e.g. here

C# Duration or Length of a media file (Metro)

I'm trying to create a media player for the Windows Store. I am using MediaElement to play the file, but I would also like to be able to load multiple songs/videos in a playlist and to display the title of the media file and the length of the file in seconds.
Something like that:
TimeSpan duration = GetFileDuration(mFile.PathToFile);
or
int durationOfFileInSeconds = GetFileDuration(mFile.PathToFile);
How can I do that ? I tried a lot of methods but they don't work because I'm trying do develop for Windows Store. I tried:
System.Windows.Media.MediaPlayer
Microsoft.WindowsAPICodecPack
Shell() and GetDetailsOf()
many other solutions that I find online
I've also tried to create a new page with a MediaElement just to load files in the MediaElement but the MediaElement.MediaOpened or the MediaElement.MediaFailed events are never fired and while ((mPlayer.NaturalDuration.TimeSpan == new TimeSpan())) ; would run indefinitely.
Really need some help with this. I've seen media players on the Windows Store that can display the duration of the file, so it's possible. I just don't know how.

EMGU QueryFrame returns "streaky" Image over RTSP

I have a HD network camera that I am trying to grab frames over rtsp and using the following code:
//in Form_Load
Application.Idle += getNextFrame;
And the Event Handler:
private void getNextFrame(object sender, EventArgs ags)
{
//where _imgCount is the total image Grabs
lbl_Count.Text = _imgCount++.ToString();
// and ibLive is a Emgu ImageBox
ibLive.Image = capAxis.QueryFrame().Resize(640, 480, INTER.CV_INTER_AREA);
}
When I start the program, it'll grab 20-40 frames before the "streakiness" appears at the bottom of the screen. It's always on the bottom of the image, but some times it takes up half the screen.
The stream resolution is 1920x1080 and it's using mjpeg. I tried switching to h.264 but had the same results.
I am using Emgu version x86-2.4.0.1717
Any Ideas?
Thanks.
I know this is an old question but I ran into the same problem recently.
I would recommend using another streaming library. Eg.
http://net7mma.codeplex.com/
http://www.fluorinefx.com/
If you really need to stream using EMGU then create a stream profile with a lower resolution or higher compression. I set compression to 30 and used the same resolution then provided the stream profile name in the rtsp url. (Assuming you're using an Axis camera like me capAxis)
Capture cap = new Capture(#"rtsp://10.0.0.1/axis-media/media.amp?videocodec=h264&streamprofile=rtspstream");
I have the same problem like that and I have solved it by myself. I used iSpy to know url of my ONVIF Ip Camera. My IP Camera's url is rtsp://192.168.1.xxx:554//user=admin_password=tlJwpbo6_channel=1_stream=0.sdp?real_stream
For stream = 0, my IP Cam is running in HD resolution (1280 x 720) and that resolution makes a streaky result of my image. So there were two options of URL that iSpy gave, and the other one is just different in stream. I changed stream = 1 for low resolution (352 x 288) and the image result is good ! There's no streaky in my image. Something that I learned from this problem was using RTSP you must use it in low resolution. High resolution will make the image result not good. Hope it can help your problem.
Regards,
Alfonsus Dhani
At the end of Capture string add this "?tcp"
Capture cap = new Capture(#"rtsp://10.0.0.1/axis-media/media.amp?videocodec=h264&streamprofile=rtspstream?tcp");
EDIT
This is my code, and yes, it works, I'am using an IP cam DAHUA.
Capture cap = Capture(#"rtsp://admin:12345#10.0.0.01:554/cam/realmonitor?channel=1&subtype=01?tcp");
A late reply but may help someone facing similar challenged.
Emgu's capabilities to deal with RTSP streams are limited and not stable. I was facing similar issues as discussion in this question,
Unable to use EMGU CV to grab images from RTSP stream continuously
The solution was to use RTSPClientSharp which works like a charm.
( https://github.com/BogdanovKirill/RtspClientSharp )

Issue with getting the duration of an audio file using the MediaPlayer class

I'm working with some Audio files in my app (mp3, wav, ..etc)
I was using the MediaPlayer class from the System.Windows.Media namespace..
but I had some problems with computing the duration of the sound file,
my form is actually a small media player, it has a TrackBar a ComboBox
and the normal next, previous and play buttons ..
I used this code to get the duration of the sound file to determine the maximum value of the track bar:
private void MusicComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
System.Windows.Duration duration = Player.NaturalDuration;
SeekBar.Value = 0;
Player.Open(new Uri(soundEffectPackage.GetMusicAt(MusicComboBox.SelectedIndex)));
if(duration.HasTimeSpan)
SeekBar.Maximum = duration.TimeSpan.Seconds;
}
This is working fine with only some of the files,
while other files don't have a TimeSpan so the if isn't getting executed, and if i removed the if, I'll get an exception saying that I should check first to see if the HasTimeSpan is true, then moving on.
How can i fix this?
How can i get the duration of the audio file ?
And what do they mean by a time span ?
Any help would be appreciated, thank you :)
According This
You need to wait for MediaOpened event to fire, NaturalDuration will be available after that. To check if value is available, you can use NaturalDuration.HasTimeSpan property.
but the best chose for working with audio and video file is "Fmod.dll".this have a lot of Privilege to work with audio file

Categories