Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mfkl committed Jun 4, 2024
1 parent bea7316 commit a254895
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
15 changes: 7 additions & 8 deletions src/LibVLCSharp.Tests/MediaPlayerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task ChapterDescriptions()
[Test]
public async Task Play()
{
var media = new Media("http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", FromType.FromLocation);
var media = new Media(new Uri(LocalAudioFile));
var mp = new MediaPlayer(_libVLC, media);
var called = false;
mp.Playing += (sender, args) =>
Expand All @@ -85,7 +85,6 @@ public async Task Play()
mp.Play();
await Task.Delay(5000);
Assert.True(called);
//Assert.True(mp.IsPlaying);
}

int callCountRegisterOne = 0;
Expand All @@ -96,7 +95,7 @@ public async Task EventFireOnceForeachRegistration()
{
try
{
var media = new Media("http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", FromType.FromLocation);
var media = new Media(new Uri(LocalAudioFile));
var mp = new MediaPlayer(_libVLC, media);


Expand Down Expand Up @@ -185,7 +184,7 @@ public async Task UpdateViewpoint()
{
var mp = new MediaPlayer(_libVLC);

mp.Play(new Media("https://streams.videolan.org/streams/360/eagle_360.mp4", FromType.FromLocation));
mp.Play(new Media(new Uri("https://streams.videolan.org/streams/360/eagle_360.mp4"), ":no-video"));

await Task.Delay(1000);

Expand All @@ -204,17 +203,17 @@ public async Task UpdateViewpoint()
public void GetMediaPlayerRole()
{
var mp = new MediaPlayer(_libVLC);
Assert.AreEqual(MediaPlayerRole.None, mp.Role);
Assert.AreEqual(MediaPlayerRole.Video, mp.Role);
}

[Test]
public void SetMediaPlayerRole()
{
var mp = new MediaPlayer(_libVLC);
Assert.AreEqual(MediaPlayerRole.None, mp.Role);

Assert.True(mp.SetRole(MediaPlayerRole.Video));
Assert.AreEqual(MediaPlayerRole.Video, mp.Role);

Assert.True(mp.SetRole(MediaPlayerRole.Music));
Assert.AreEqual(MediaPlayerRole.Music, mp.Role);
}

[Test]
Expand Down
13 changes: 9 additions & 4 deletions src/LibVLCSharp.Tests/MediaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,19 @@ public void AddOption()
}

[Test]
public async Task CreateRealMedia()
public async Task CheckStats()
{
using var media = new Media(new Uri(LocalAudioFile));
using var media = new Media(new Uri(RemoteVideoStream));
Assert.NotZero(media.Duration);
using var mp = new MediaPlayer(_libVLC, media);

Assert.True(mp.Play());
await Task.Delay(4000); // have to wait a bit for statistics to populate
Assert.Greater(media.Statistics.DemuxBitrate, 0);

await Task.Delay(5000); // have to wait a bit for statistics to populate

Assert.NotZero(media.Statistics.DemuxBitrate);
Assert.NotZero(media.Statistics.ReadBytes);

mp.Stop();
}

Expand Down
8 changes: 4 additions & 4 deletions src/LibVLCSharp/Structures/MediaTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public MediaTrack? this[uint position]

internal class MediaTrackListEnumerator : IEnumerator<MediaTrack>
{
uint position = 0;
int position = -1;
MediaTrackList? _mediaTrackList;

internal MediaTrackListEnumerator(MediaTrackList mediaTrackList)
Expand All @@ -327,12 +327,12 @@ public bool MoveNext()

void IEnumerator.Reset()
{
position = 0;
position = -1;
}

public void Dispose()
{
position = 0;
position = -1;
_mediaTrackList = default;
}

Expand All @@ -346,7 +346,7 @@ public MediaTrack Current
{
throw new ObjectDisposedException(nameof(MediaTrackListEnumerator));
}
return _mediaTrackList[position] ?? throw new ArgumentOutOfRangeException(nameof(position));
return _mediaTrackList[position < 0 ? 0 : (uint)position] ?? throw new ArgumentOutOfRangeException(nameof(position));
}
}
}
Expand Down

0 comments on commit a254895

Please sign in to comment.