Send RTSP Authentication C# - c#

I am simply trying write a program in C# (windows forms) to play a video from an acquired URI that is password protected. The point of the program was to locate a URI using SOAPs and other means in order to stream a specific video feed. I didn't know the most difficult part of the project would be simply playing the video. I assumed there had to be libraries out there that could handle this. While there is plenty that can play a video, I am struggling to figure out how to handle RTSP streaming with authentication.
Tried formatting the URI object with UserName and Password. This throws a bad formatting error. Even though the final results follows good formatting according Wiki "IsWellFormedUriString" still throws an error.
local_uri.Host = deviceUri.Host;
local_uri.Port = 554;
local_uri.Scheme = "rtsp";
local_uri.Password = "admin";
local_uri.UserName = "admin";
//List full URI info.
infoBox.Text = local_uri.ToString();
//Past it to VideoView and start playing video.
bool check = Uri.IsWellFormedUriString(local_uri.Uri.ToString(), UriKind.RelativeOrAbsolute);
bool check = true;
if (check)
{
//_mp is of type LibVlcSharp.Shared.MediaPlayer
_mp.Play(new Media(_libVLC, local_uri.Uri));
check = false;
}
else
check = false;
I've tired to get a depreciated version of the VLC library working but seem to be running into the same issues. Looked through c# VLC lib and didn't find any function that would obviously handle authorization. I then started just trying to write code to handle, buffer, and play the data. I think this will be out of the question for how time consuming it is and given the time constrains on this assignment.
I know the URI i get back is valid. I can open VLC and entire the URI. A moment later the following pops up...
Once its entered I see a RTSP package sent to the URL...
DESCRIBE rtsp://192.168.1.64:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1 RTSP/1.0
CSeq: 7
Authorization: Digest username="admin", realm="IP Camera(C6990)", nonce="61218496a6adcf4869f748505626d63a", uri="rtsp://192.168.1.64:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", response="3cce04175b5b1a3d0a6a8dcfea9d377a"
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp
Then of course the URL responds with an 200 Ok and starts streaming. It would be great if I could figure out how to recreate this event in C#. I had a recommendations of doing a Dialog API but cannot figure out how to work that out with the VLC Object. Any direction would be greatly appreciated. Hindsight I should not have chosen a different project as this is attached to my grade.

As it turns out (and I'm not entirely sure why) but the code above does work as long as your password does not contain anything that would cause string formatting error. For example, the password cannot contain an "#" symbol with the code above. I'm sure there is a workaround for this but have not figured out what it is.

Related

intermittent 412 error when calling Google Directory API to patch a user's password

My application's main function is to change a Google G-Suite user's password using Google's Google.Apis.Admin.Directory.directory_v1 nuget package.
The API call works 95% of the time (and resets a target user's password), but intermittently, the API call throws an exception with the Message text:
Precondition Failed [412] Errors [ Message[Precondition Failed] Location[If-Match - header] Reason[conditionNotMet] Domain[global] ]
I've done lots of research and it seems that there is a client-specified pre-condition being included in a (REST?) call that the API is making toward the Google API server and the server is determining that the condition is not being met (see https://www.rfc-editor.org/rfc/rfc7232#section-4.2) or the state of the object being changed is bad (https://developers.google.com/calendar/v3/errors ). The strange thing is, everything does work nearly all of the time, but then fails every now and then. It really seems like it is some kind of a resource based error (too many calls submitted recently, too many users licensed in the domain) or maybe bad data (bad or missing password, bad user) or even permissions (user is in a group/OU that can'b be managed). But the error message gives nothing to go on and I've mostly ruled out the most obvious of the possibilities. I've googled the exact message and found numerous people with similar complaints, but no documented causes.
Correction from original: I am able to capture REST calls with Fiddler (with https capture configured), but I can't reproduce the original error while capturing, so it doesn't help much.
Any suggestions for how to reproduce and/or troubleshoot the issue?
Here is the code (please ignore any obvious typos-I had to cut/paste/merge from a few sources to assemble a small simple example)--the real code definitely works nearly all of the time:
{
userEmail = googleUser + "#" + domain; // e.g. BobSmith#myGoogleDomain.com
// service is an instance of Google.Apis.Admin.Directory.directory_v1.DirectoryService
var userget = service.Users.Get(userEmail);
User userob = userget.Execute();
userob.ChangePasswordAtNextLogin = false;
userob.Password = password;
patchRequest=service.Users.Patch(userob, userEmail);
patchRequest.Execute();
}
catch (Exception e)
{}

Unity Play Games can't authenticate

I have a issue with play games services and unity.
I've done everything by the documentation. I'm a tester, testing is allowed and I've changed the sha1 in api console to the one used by the app. I'm using code from the docs and examples so here is a brief:
PlayGamesClientConfiguration conf = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(conf);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
Debug.Log("Authenticating...");
Social.localUser.Authenticate((bool success) =>
{
if (success)
{
Debug.Log("Welcome " + Social.localUser.userName);
}
else
{
Debug.Log("Authentication failed.");
}
});
When I build the app in development mode the Play Games popup appears, starts loading and disappears and gives me a Authentication failed message. But when I build the app without the development mode nothing happens and I get the authentication failed message instantly. And yes I'm the correct sha1 key.
Please help me
I did a number of things and finally got it to work. I cannot be sure if they all contributed to solving this issue so here I will list what I did, from greatest to least of my guess of their relevance:
Match the SHA-1 certificates. If you are using an app downloaded from Play Store use the "app signing certificate", else use the upload certificate. These are found in the Play Console under YourApp/Release Management/App Signing. As a note, if you are building from Unity directly to your device, you should make sure that you are building with the same key used to upload to Google Play. More info here
If you are using a custom config and are requesting things such .RequestServerAuthCode(false), you must create an additional Web App. Go to your console project, and under create credentials choose OAuth client ID, and then select Web App.
If using internal testing, make sure to authorize accounts in the Play Console under Game Services/Your App/Testing.
Try disabling Anti-Piracy in the Play Console under Game Services/Your App/Linked Apps/Your App. Only do this if you are testing app outside Google Play. I think if you are logging in using verified test accounts this doesn't matter.
Edit: Publishing Game Services is required even for testing.. at least that seemed to be the case for me to get it working.
Try clearing the cache of your App on your device, I ran into this problem again and this solved it for me.
I finally think I have got it fixed for good.. after nearly a month later. :o Hope this helps.
Google Services can be published/unpublished separately from your app.
Check if they are correctly published doing the following:
Google Play Console
Game services
Select your game
Publishing
Check if Game Services are published.

C# .NET Core Discord Music Bot

so I'm looking to code in some music functionality to a bot that I'm making. I've tried a whole bunch of different search terms but can't seem to come up with anything.
I'm writing the bot in C# .NET Core
I've got the basics down. Connects to a voice channel etc. But I'm not sure how to interface it with YouTube/Spotify so that it could search for url's or song titles.
So for example I'd like to be able to give it a link like this (either youtube or spotify):
Or be able to search Youtube (or both) for a song title:
I'm sure there's some kind of library to download or a NuGet package or API that I can integrate, but I just can't seem to find the right search terms to use to find any tutorials or documentation on the topic.
Any help in this area would be appreciated
Well I have been in your shoes and the best solution is to abandon all native ffmpeg and all and just use Sharplink. It uses lavalink to send audio to discord without actually connecting to it.
DiscordSocketClient client = new DiscordSocketClient();
LavalinkManager lavalinkManager = new LavalinkManager(client, new LavalinkManagerConfig
{
RESTHost = "localhost",
RESTPort = 2333,
WebSocketHost = "localhost",
WebSocketPort = 2333,
Authorization = "YOUR_SECRET_AUTHORIZATION_KEY",
TotalShards = 1
});
This is how you would get started.
Once a LavalinkManager is set up it will need to be started. It is recommended you put this in the ready event.
client.Ready += async () =>
{
await lavalinkManager.StartAsync();
}
Real the docs at https://github.com/Devoxin/SharpLink
Good Luck
**EDIT: **
I made my music bot public so https://github.com/rishav394/Dota-Geek/ here it is. Look out for the music section.

Programmatically downloading apk from web using Xamarin

I coded an app and I am trying to download a apk from my webspace now. I googled the whole day now and everything I found was for Java I think, but I need C#.
This is what I found (not only this but it's an example): Downloading APK from server and installing it to device (but it's not working I don't know why).
But I have some problems with the code. I can't use the setRequestMethod or getinputstream etc.
Then I tried out this because it seemed to be much easier:
WebClient webClient = new WebClient();
Uri newUri = new Uri("http://mywebspace.bplaced.net/AppDownload.apk");
webClient.DownloadFile(newUri,Path.Combine(Android.OS.Environment.DirectoryDownloads, "AppDownload.apk"));
This is also not working. I'm getting the message "parts of the path not found" (kinda like this, my Visual Studio isn't in English). Doesn't matter what I enter as my path.
This seems to be a duplicate question, which already has been answered here: How to download a file from a URL in C#?
Nevertheless, I have tested your code and for me it is working. I am able to download a file from an url. So, my guess is, that you have a typo in your URL, a problem with the firewall, etc.
Please copy the URL you have entered in the source code and paste it to a Browser of your choice. And see if the download starts. Just to be sure that the URL is correct.
It would better to provide us with the whole error message.

How can I configure network access for the Windows Phone emulator?

I'm trying to debug an application that is making a WebRequest synchronously, ie.:
HttpWebRequest req = WebRequest.Create(new Uri("http://www.stackoverflow.com/")) as HttpWebRequest;
IAsyncResult res = req.BeginGetResponse(callback => { }, req);
while (!res.IsCompleted)
{
System.Threading.Thread.Sleep(100);
}
// Doesn't matter what's here, as `res.IsCompleted` never returns true
This is just to check that some of the application logic is "right", but it's getting stuck, with the IAsyncResult never reporting itself as complete.
To check, things, I tried to use Internet Explorer on the emulator, but found that is unable to find any webpages (including the built in favourites), which makes me think that the emulator is trying to use a specific network interface on my laptop, but there doesn't seem to be any way to configure it, or which interface to use? I have a suspicion that it may be trying to use a VPN interface, or a virtual adaptor like the one for VirtualBox. So, how can I configure it? additionally, would you expect requests made by the emulator to show up in Fiddler?
For the record, NetworkInterface.GetIsNetworkAvailable() returns true;
UPDATE:
It appears that updating my graphics driver (and associated reboot) allowed the emulator to access the real network (or at least guess the right adapter); however, res.IsCompleted still doesn't report true (and Fiddler shows the request has completed), so I'm a little confuddled.
Are you using a proxy? The Windows Phone emulator is tied to the currently active Internet Connection, as well as the proxy settings. Make sure those are set up correctly. Also, there might be a firewall blocking Internet access for XDE - check the settings too.
I would recommend getting Fiddler. Attempt to configure it to capture emulator traffic and see what information you can get from there.

Categories