youtube api updating video information using asp.net - asp.net

I am using the Youtube api for asp.net to rename a video:
public static void UpdateVideoInfo(string video_id, string new_title)
{
Uri entry = new Uri("http://gdata.youtube.com/feeds/api/videos/" + video_id);
Video video = AuthRequest().Retrieve<Video>(entry);
if (video.ReadOnly == false)
{
video.Title = new_title;
}
else video.Title = video.Title;
Video updatedvideo = AuthRequest().Update(video);
}
but i get this error:
Object reference not set to an instance of an object
on the last line.
what am i doing wrong?
thanks

May be is the same problem reported here, with a different error message..
YouTube API .NET C# editing video problem

Related

Xamarin Forms NAudio

I need some advice.
I found this ShazamApi project that uses NAudio. I need this project to work in Xamarin Forms (Android), but I don't know what to use instead of NAudio to make it work on Android. Someone would know how to do it. Thanks a lot.
Specifically, I have a problem with this code.
https://github.com/AlekseyMartynov/shazam-for-real/blob/master/Program.cs
https://github.com/AlekseyMartynov/shazam-for-real/blob/master/Analysis.cs
public void ReadChunk(ISampleProvider sampleProvider)
{
if(sampleProvider.Read(WindowRing, WindowRingPos, CHUNK_SIZE) != CHUNK_SIZE)
throw new Exception();
ProcessedSamples += CHUNK_SIZE;
if(ProcessedSamples >= WINDOW_SIZE)
AddStripe();
}
WasapiLoopbackCapture capture = new WasapiLoopbackCapture();
var captureBuf = new BufferedWaveProvider(capture.WaveFormat);
capture.DataAvailable += (s, e) =>
{
captureBuf.AddSamples(e.Buffer, 0, e.BytesRecorded);
};
capture.StartRecording();
using (var resampler = new MediaFoundationResampler(captureBuf, new WaveFormat(Analysis.SAMPLE_RATE, 16, 1)))
{
var sampleProvider = resampler.ToSampleProvider();
var retryMs = 3000;
var tagId = Guid.NewGuid().ToString();
while (true)
{
while (captureBuf.BufferedDuration.TotalSeconds < 1)
Thread.Sleep(100);
analysis.ReadChunk(sampleProvider);
if (analysis.StripeCount > 2 * LandmarkFinder.RADIUS_TIME)
finder.Find(analysis.StripeCount - LandmarkFinder.RADIUS_TIME - 1);
if (analysis.ProcessedMs >= retryMs)
{
var sigBytes = Sig.Write(Analysis.SAMPLE_RATE, analysis.ProcessedSamples, finder);
var result = ShazamApi.SendRequest(tagId, analysis.ProcessedMs, sigBytes).GetAwaiter().GetResult();
if (result.Success)
return result;
retryMs = result.RetryMs;
if (retryMs == 0)
return result;
}
}
}
but I don't know what to use instead of NAudio to make it work on
Android.
In xamarin forms, you can use Xamarin Community Toolkit MediaElement to achieve this function.
MediaElement is a view for playing video and audio. Media that's supported by the underlying platform can be played from the following sources:
The web, using a URI (HTTP or HTTPS).
A resource embedded in the platform application, using the
ms-appx:/// URI scheme.
Files that come from the app's local and temporary data folders,
using the ms-appdata:/// URI scheme.
The device's library.
There is also a official sample here: Xamarin Community Toolkit - MediaElement.
Note:
In android, you can also try Android Audio. The Android OS provides extensive support for multimedia, encompassing both audio and video.

How do I parse specific data from a website within Codename One?

I have run into a road block developing my Codename One app. One of my classes in my project parses 3 specific html "td" elements from a website and saves the text to a string where I then input that text data into a Codename One multibutton. I originally used jSoup for this operation but soon realized that Codename One doesn't support 3rd party jar files so I used this method as shown below.
public void showOilPrice() {
if (current != null) {
current.show();
return;
}
WebBrowser b = new WebBrowser() {
#Override
public void onLoad(String url) {
BrowserComponent c = (BrowserComponent) this.getInternal();
JavascriptContext ctx = new JavascriptContext(c);
String wtiLast = (String) ctx.get("document.getElementById('pair_8849').childNodes[4].innerText");
String wtiPrev = (String) ctx.get("document.getElementById('pair_8849').childNodes[5].innerText");
String wtiChange = (String) ctx.get("document.getElementById('pair_8849').childNodes[8].innerText");
Form op = new Form("Oil Prices", new BoxLayout(BoxLayout.Y_AXIS));
MultiButton wti = new MultiButton("West Texas Intermediate");
Image icon = null;
Image emblem = null;
wti.setEmblem(emblem);
wti.setTextLine2("Current Price: " + wtiLast);
wti.setTextLine3("Previous: " + wtiPrev);
wti.setTextLine4("Change: " + wtiChange);
op.add(wti);
op.show();
}
};
b.setURL("https://sslcomrates.forexprostools.com/index.php?force_lang=1&pairs_ids=8833;8849;954867;8988;8861;8862;&header-text-color=%23FFFFFF&curr-name-color=%230059b0&inner-text-color=%23000000&green-text-color=%232A8215&green-background=%23B7F4C2&red-text-color=%23DC0001&red-background=%23FFE2E2&inner-border-color=%23CBCBCB&border-color=%23cbcbcb&bg1=%23F6F6F6&bg2=%23ffffff&open=show&last_update=show");
}
This method works in the simulator (and gives a "depreciated API" warning), but does not run when I submit my build online after signing. I have imported the parse4cn1 and cn1JSON libraries and have gone through a series of obstacles but I still receive a build error when I submit. I want to start fresh and use an alternative method if one exists. Is there a way that I can rewrite this segment of code without having to use these libraries? Maybe by using the XMLParser class?
The deprecation is for the WebBrowser class. You can use BrowserComponent directly so WebBrowser is redundant in this case.
I used XMLParser for this use case in the past. It should work with HTML as it was originally designed to show HTML.
It might also be possible to port JSoup to Codename One although I'm not sure about the scope of effort involved.
It's very possible that onLoad isn't invoked for a site you don't actually see rendered so the question is what specifically failed on the device?

ASP.NET Web API 2 file upload

I would like to know how best to handle file upload and addtional information added to the file to be uploaded using ASP.NET Web API 2 without MVC components. I have google the net and I can tell you I am more confused than I expected.
The Additional info will be stored in db and the file on the disk.
So far the Web API app I am building does not support multipart/form-data. It only supports the default media types. I know I need to create a media formatter.
Pls help.
I had wrote Javascript split File and upload to WEB API . i think you can reference my backend codes
In front-end you need using below code to upload your File
var xhr = new self.XMLHttpRequest();
xhr.open('POST', url, false);
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.send(chunk);
In backend use Request.InputStream.Read to catch your file bytes
[HttpPost]
[ValidateInput(false)]
public string fileUpload(string filename)
{
byte[] file = new byte[Request.InputStream.Length];
Request.InputStream.Read(file, 0, Convert.ToInt32(Request.InputStream.Length));
BinaryWriter binWriter = new BinaryWriter(new MemoryStream());
binWriter.Write(file);
StreamReader reader = new StreamReader(binWriter.BaseStream);
reader.BaseStream.Position = 0;
//This example is recevied text file
while ((line = reader.ReadLine()) != null)
{
};
}
You can just serialize your file data into BASE64 and send them as a string in case of multipart/from-data is not allowed for some reason.

Creating expiring links to S3 or Cloudfront hosted content with ASP .Net

Anyone have an example of creating a signed URL with an expiration using ASP .Net? I'm exploring using LitS3 or ThreeSharp in my project, and have not seen any specific methods to do this in either of those projects. Thanks.
Here's what worked for me with the AWS SDK and MVC 3 (based on the answers above and what I found on http://www.ec2studio.com/articles/s3.html):
public ActionResult GetS3Object(string bucket, string key)
{
string accessKeyID = ConfigurationManager.AppSettings["AWSAccessKey"];
string secretAccessKeyID = ConfigurationManager.AppSettings["AWSSecretKey"];
using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID))
{
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest()
.WithBucketName(bucket)
.WithKey(key)
.WithExpires(DateTime.Now.Add(new TimeSpan(7, 0, 0, 0)));
return Redirect(client.GetPreSignedURL(request));
}
}
using the amazon .net SDK
you can get preSignedUrl
using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client("your access key ID", "you secret key"))
{
GetPreSignedUrlRequest getPreSignedUrl = new GetPreSignedUrlRequest().WithBucketName(bucketName);
getPreSignedUrl.Key = key;
getPreSignedUrl.Expires = DateTime.Now.AddSeconds(60);
}
Found this (mentioned in this thread in the AWS discussion forums) class library for generating signed URLs in Amazon S3. If anyone has any additional suggestions/methods to try, let me know.
Edit: ThreeSharp has the functionality I was looking for. From the ThreeSharpConsoleSample app:
using (UrlGetRequest request = new UrlGetRequest("mytestbucket", "mytestfile.txt"))
{
request.ExpiresIn = 60 * 10000;
using (UrlGetResponse response = service.UrlGet(request))
{
Console.WriteLine("Try this url in your web browser (it will only work for 60 seconds)\n");
string url = response.StreamResponseToString();
Console.WriteLine(url);
}
}
Console.WriteLine("\npress enter >");
Console.ReadLine();

Get the status of a live stream for a VideoDisplay control

I'm looking for a way to find the status of a live stream through a VideoDisplay (or any other method really). I am interested to know if the stream is currently being published to or if the publisher has stopped. This is for a Flex/Flash ActionScript 3 project.
Is there a way to do this or is this ANOTHER oversight by adobe?
flex flash adobe adobe-flex actionscript
I've only found one solution, and that's using the NetStream object in combination with a video control.
The video control must be manually added to an
nsListen = new NetStream(nc);
nsListen.addEventListener(NetStatusEvent.NET_STATUS, nsListenHandler);
nsListen.play(streamname);
var v:Video = new Video();
v.attachStream(nsListen);
uicontrol.add(v);
Finally, the event status is returned in nsListenHandler:
private function nsListenHandler(e:Event):void
{
if(e is NetStatusEvent)
{
var nse:NetStatusEvent = NetStatusEvent(e);
if(nse.info.code == "NetStream.Play.Failed")
{
// Big error.
}
if(nse.info.code == "NetStream.Play.PublishNotify")
{
// Stream has just been published
}
if(nse.info.code == "NetStream.Play.UnpublishNotify")
{
// Stream has just been unpublished
}
trace(NetStatusEvent(e).info.code);
trace(NetStatusEvent(e).info.description);
}
}
Only this code wont do is tell you if a stream is already successfully being published to.
You can dig into NetStatusEvent events.
Check this live docs

Resources