libVLCSharp fail to create MediaList - c#

I'am playing arround with libVLCSharp and I found a wired behavior. Actually I have no problem creating a media and playing it with MediaPlayer. However when I try to create a Media from MediaList it breaks with the followig message:
Failed to perform instanciation on the native side. Make sure you
installed the correct VideoLAN.LibVLC.[YourPlatform] package in your
platform specific project
What I wanted to achive is video merging using ":sout=#gather" pipe.
My code is very basic :
Core.Initialize();
using (var libvlc = new LibVLC())
using (var mediaPlayer = new MediaPlayer(libvlc))
{
Media media1 = new Media(libvlc, #"C:\Temp\SampleVideo.mp4");
Media media2 = new Media(libvlc, #"C:\Temp\SampleVideo.mp4");
MediaList list = new MediaList(libvlc);
list.AddMedia(media1);
list.AddMedia(media2);
Media mediaList = new Media(list); <-- Error here
...
}
I have 2 nuget packages used in my project:
LibVLCSharp v3.0.2 June 12
VideoLAN.LibVLC.Windows v3.0.7 June 10

You want to be using SetMedia for this, not AddMedia.
Associate media instance with this media list instance.
https://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__list.html#ga96a38e5aabb5781c2f1932d332363eef
Core.Initialize();
using(var libVLC = new LibVLC())
{
var media1 = new Media(libVLC, "https://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4", FromType.FromLocation);
var mediaList = new MediaList(libVLC);
mediaList.SetMedia(media1);
var media2 = new Media(mediaList);
}

Related

Newbie Lucene Problem with c# demo "The Type or Namespace 'StandardAnalyzer' could not be found"

I'm trying to get the basic demo of Lucene.net (4.8.0-beta00012) to run.
http://lucenenet.apache.org/#quick-start
I've created a new Forms App.
Run Install-Package Lucene.Net -Pre and it's downloaded the nuget package.
Copied and pasted all the demo sections: Create an index and define a text analyzer, Add to the index, Construct a query, and Fetch the results.
Visual Studio popped up a load of missing assembly references so I clicked 'Potential Fixes' and let it add the using statements at the start.
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Store;
using Lucene.Net.Util;
using System;
using System.Windows.Forms;
namespace Lucene_CS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Ensures index backwards compatibility
var AppLuceneVersion = LuceneVersion.LUCENE_48;
var indexLocation = #"C:\Index";
var dir = FSDirectory.Open(indexLocation);
//create an analyzer to process the text
var analyzer = new StandardAnalyzer(AppLuceneVersion);
//create an index writer
var indexConfig = new IndexWriterConfig(AppLuceneVersion, analyzer);
var writer = new IndexWriter(dir, indexConfig);
var source = new
{
Name = "Kermit the Frog",
FavoritePhrase = "The quick brown fox jumps over the lazy dog"
};
Document doc = new Document
{
new StringField("name",
source.Name,
Field.Store.YES),
new TextField("favoritePhrase",
source.FavoritePhrase,
Field.Store.YES)
};
writer.AddDocument(doc);
writer.Flush(triggerMerge: false, applyAllDeletes: false);
// search with a phrase
var phrase = new MultiPhraseQuery
{
new Term("favoritePhrase", "brown"),
new Term("favoritePhrase", "fox")
};
// re-use the writer to get real-time updates
var searcher = new IndexSearcher(writer.GetReader(applyAllDeletes: true));
var hits = searcher.Search(phrase, 20 /* top 20 */).ScoreDocs;
foreach (var hit in hits)
{
var foundDoc = searcher.Doc(hit.Doc);
hit.Score.Dump("Score");
foundDoc.Get("name").Dump("Name");
foundDoc.Get("favoritePhrase").Dump("Favorite Phrase");
}
}
}
}
Now I am left with a couple that won't resolve:
var analyzer = new StandardAnalyzer(AppLuceneVersion);
And .Dump
hit.Score.Dump("Score");
foundDoc.Get("name").Dump("Name");
foundDoc.Get("favoritePhrase").Dump("Favorite Phrase");
How would I go about debugging this to determine how to specify the references correctly?
UPDATE WITH namespace Lucene.Net.Analysis.Standard
StandardAnalyzer is located in namespace Lucene.Net.Analysis.Standard.
I don't have an answer for you with regard to .Dump exactly.
hit.Score is a float, so hit.Score.Dump("Score"); is a bit hard for me to imagine. I did a search of the lucene net repository for the word Dump and there are only 20 occurrences. https://github.com/apache/lucenenet/search?p=1&q=Dump
One of them is the code tutorial example you are citing. But none of the other occurrences appear to be the implementation of that Dump method. So I'm gonna guess that the .Dump is no longer a valid method for the uses cited.
I'd recommend changing
foreach (var hit in hits)
{
var foundDoc = searcher.Doc(hit.Doc);
hit.Score.Dump("Score");
foundDoc.Get("name").Dump("Name");
foundDoc.Get("favoritePhrase").Dump("Favorite Phrase");
}
to
foreach (var hit in hits)
{
var foundDoc = searcher.Doc(hit.Doc);
var score = hit.Score;
var name = foundDoc.Get("name");
var favoritePhrase = foundDoc.Get("favoritePhrase");
}
That will probably work for you and allow you to inspect the fields retrieved via the debugger.
I might add that while the info on Lucene.Net can seem a bit limiting for a beginner, the system is amazing and crazy powerful. I say that to encourage you as you are learning it because it's well worth learning. I love it.
Update
Just as #bendecko said in the comment below, you need to install the package Lucene.Net.Analysis.Common from NuGet. Sorry I didn't specify that when providing the namespace.

Getting current location in a WPF C# app using Geocode.Core

I'm trying to get the lat/lng of my current location of my win7 PC, I'm using Bing maps. I've had some words with the guys at the SO C# chat room and they told me about this github project. Now I've downloaded the NuGet components: Geocoding.Core and Geocoding.Microsoft
In the example provided, an IGeocoder should be instantiated as follows:
IGeocoder geocoder = new GoogleGeocoder() { ApiKey = "this-is-my-optional-google-api-key" };
Now what I'm trying to do is using MicrosoftGeocoder instead. But the IDE doesn't seem to have this kind of constructor, the new keyword won't give me that option. Here's my code:
public MainWindow()
{
InitializeComponent();
MainMap.Mode = new AerialMode(true);
MainMap.Focus();
MainMap.Culture = "ar-sa";
MainMap.MouseDoubleClick += new MouseButtonEventHandler(MapWithPushpins_MouseDoubleClick);
IGeocoder geocoder = new MicrosoftGeocoder("KEY HERE");
}
I should say that I haven't dealt with github very much so excuse my ignorance if I'm missing something.
There is no MicrosoftGeocoder type available in Geocoding.Microsoft but the constructor of BingMapsGeocoder accepts a key:
IGeocoder geocoder = new BingMapsGeocoder("KEY HERE");

Play audio url using xamarin MediaPlayer

Why xamarin MediaPlayer (on Xamarin.Android) can play audio as a stream from a link like this (mediaUrl1) :
https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3
But can't do it from a link like this (mediaUrl2):
http://api-streaming.youscribe.com/v1/products/2919465/documents/3214936/audio/stream
private MediaPlayer player;
//..
player = new MediaPlayer();
player.SetAudioStreamType(Stream.Music);
//..
await player.SetDataSourceAsync(ApplicationContext, Android.Net.Uri.Parse(mediaUrl));
//..
player.PrepareAsync();
//..
Is there a way to play the link above (mediaUrl2) without (of course) downloading the file first?
Here is the full source of the sample i am using. Any help would be appreciated.
http://api-streaming.youscribe.com/v1/products/2919465/documents/3214936/audio/stream
That is an HTTP mpga stream and is not directly supported by any of the Android APIs that I know of and thus is not supported by MediaPlayer (consult the Android Support Media Formats for further reading).
You can review the logcat output of your MediaPlayer code and you will see output like:
[MediaPlayerNative] start called in state 4, mPlayer(0x8efb7240)
[MediaPlayerNative] error (-38, 0)
[MediaPlayer] Error (-38,0)
[MediaHTTPConnection] readAt 1161613 / 32768 => java.net.ProtocolException
[MediaHTTPConnection] readAt 1161613 / 32768 => java.net.ProtocolException
[MediaPlayerNative] error (1, -2147483648)
[MediaPlayer] Error (1,-2147483648)
Google's Android ExoPlayer can stream that media format properly.
This is a really simple and very crude example of ExoPlayer, but it will show you that it does play that stream:
ExoPlayer Example:
var mediaUrl = "http://api-streaming.youscribe.com/v1/products/2919465/documents/3214936/audio/stream";
var mediaUri = Android.Net.Uri.Parse(mediaUrl);
var userAgent = Util.GetUserAgent(this, "ExoPlayerDemo");
var defaultHttpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent);
var defaultDataSourceFactory = new DefaultDataSourceFactory(this, null, defaultHttpDataSourceFactory);
var extractorMediaSource = new ExtractorMediaSource(mediaUri, defaultDataSourceFactory, new DefaultExtractorsFactory(), null, null);
var defaultBandwidthMeter = new DefaultBandwidthMeter();
var adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
var defaultTrackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
exoPlayer = ExoPlayerFactory.NewSimpleInstance(this, defaultTrackSelector);
exoPlayer.Prepare(extractorMediaSource);
exoPlayer.PlayWhenReady = true;
Note: exoPlayer is a class-level variable of SimpleExoPlayer type
Note: this is using the Xamarin.Android binding libraries from the Xam.Plugins.Android.ExoPlayer package
ExoPlayer Docs:
https://developer.android.com/guide/topics/media/exoplayer

How to display badges in live tile for windows UAP using NotificationsExtensions.Win10 package?

I am creating a Windows 10 application. I need to display badges in live tile. I installed NotificationsExtensions.Win10 Nuget package.I use the following code.
public static void UpdateTileBadgeNumberUsingNotificationExtensions()
{
BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(2);
BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badgeContent.CreateNotification());
}
Here CreateNotification method is not available on badgeContent.How can I implement badge count using NotificationsExtensions.Win10 Nuget package.
var badge = new BadgeNumericNotificationContent(2);
XmlDocument bdoc = content.GetXml();
BadgeNotification bnotification = new BadgeNotification(bdoc);
BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(bnotification);
Please update your code as follows:
BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(2);
BadgeNotification bnotification = new BadgeNotification(badgeContent.GetXml());
BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(bnotification);
After you have created a new BadgeNumericNotificationContent instance, you just got a content. You need to call GetXml() from this content and set the xml document to a BadgeNotification instance. Then you can update the badge by the BadgeNotification.

Storing RTSP to a file location

I am able to stream an rtsp on windows 7 64 bit machine through C# Winform application. This is the library i used - VLCDotNet and here is the code sample to play the RTSP stream:
LocationMedia media = new LocationMedia(#"rtsp://192.168.137.73:554/live.sdp");
vlcControl1.Media = media;
vlcControl1.Play();
I would like to store the streams to a file in my PC on a button click and stop the same with another button. How do i achieve this?
Here is the code:
Vlc.DotNet.Core.Medias.MediaBase media1
= new Vlc.DotNet.Core.Medias.PathMedia("rtsp://192.168.137.73:554/live.sdp");
media.AddOption(":sout=#transcode{vcodec=theo,vb=800,
scale=1,acodec=flac,ab=128,channels=2,samplerate=44100}:std{access=file,mux=ogg,
dst=D:\\123.mp4}");
VlcControl control = new VlcControl();
control.Media = media;
control.Play();
VlcContext.StartupOptions.IgnoreConfig = true;
VlcContext.StartupOptions.LogOptions.LogInFile = true;
VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = true;
VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.Debug;
// Disable showing the movie file name as an overlay
// VlcContext.StartupOptions.AddOption("--no-video-title-show");
// VlcContext.StartupOptions.AddOption("--no-audio");
VlcContext.StartupOptions.AddOption("--rtsp-tcp"); //this line was important to make this work
As of Vlc.DotNet.Core 2.1.62, The way to do this is use the extra opts param of the .Play on the vlc control.
var opts = new string[] { #":sout=file/ogg:C:\video.ogg" };
vlc.MediaPlayer.Play(new Uri(videoURI), opts);
`

Categories