How to Stream Audio (Radio ) MvvmCross - c#

I am having some difficulty stream online radio in Android Using MvvmCross. I found the plugin Xamarin MediaManager and tried to go that route.
Here's the code:
public IMvxCommand ListenCommand => new MvxCommand(Play);
private void Play()
{
CrossMediaManager.Current.Play("http://ic2.christiannetcast.com/wayg-fm");
}
In my axml, there is a button bound to that command and pressing it outputs this in the console:
[MediaPlayer] Couldn't open http://ic2.christiannetcast.com/wayg-fm: java.io.FileNotFoundException: No content provider: http://ic2.christiannetcast.com/wayg-fm
I've tested it with several different links just to make sure that wasn't't the case. Also, I've made sure to have <uses-permission android:name="android.permission.INTERNET" /> in my AndroidManifest.xml
I've also tried using Android's MediaPlayer, but I get the exact same result.
Please let me know if there is something I am missing. I haven't found any solutions online regarding this issue. Thanks!
EDIT
I am running this on an Android emulator, not a real phone. Don't know if this makes a difference.

[MediaPlayer] Couldn't open xxx java.io.FileNotFoundException: No content provider: xxx
void setDataSource(String path):
Sets the data source (file-path or http/rtsp URL) to use.
#param path the path of the file, or the http/rtsp URL of the stream you want to play
setDataSource(Context context, Uri uri):
Sets the data source as a content Uri.
#param uri the Content URI of the data you want to play
which assumes URI to be of some form of ContentProvider
Solution:
Change your MediaPlayer SetDataSource method from:
mediaPlayer.SetDataSource(context, Android.Net.Uri.Parse(url));
To:
mediaPlayer.SetDataSource(url);
I test it on my side and it works fine:
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.Reset();
mediaPlayer.SetDataSource("https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3");
mediaPlayer.Prepare();
mediaPlayer.Start();

Related

Raise Azure VM from marketplace image via C#

Failing to raise an azure VM from a marketplace image programatically.
The code:
var linuxVM = await _azure.VirtualMachines.Define(linuxVmName)
.WithRegion(Region)
.WithExistingResourceGroup(rgName)
.WithNewPrimaryNetwork("10.0.0.0/28")
.WithPrimaryPrivateIPAddressDynamic()
.WithoutPrimaryPublicIPAddress()
.WithSpecificLinuxImageVersion(new ImageReference())
.WithRootUsername(userName)
.WithRootPassword(password)
.WithSize(VirtualMachineSizeTypes.StandardNC6sV3)
.WithPlan(new PurchasePlan("nvidia", "ngc-base-version-20-10-1", "ngc_azure_17_11"))
.CreateAsync();
In Azure I've enabled "Want to deploy programmatically? Get started" for the given image (as explained here).
There are several options as to the method that selects the image, not sure which method should be used and with which parameters. Tried several combinations, but all returned misc error messages.
Did not find code samples more detailed this (which does not explain how to use an image from the marketplace).
Edit:
The code above returns this exception:
Microsoft.Rest.Azure.CloudException: 'This resource was created without a plan. A new plan cannot be associated with an update.'
Another attempt with more populated parameters causes the same exception:
.WithSpecificLinuxImageVersion(new ImageReference(new ImageReferenceInner(
publisher: "nvidia",
offer: "ngc_azure_17_11",
sku: "ngc-base-version-20-10-1"
)))
The missing parameter was the image's version. The code to raise the image looks like so:
var vm = await _azure.VirtualMachines.Define(linuxVmName)
.WithRegion(_region)
.WithExistingResourceGroup(_rgName)
.WithNewPrimaryNetwork("10.0.0.0/28")
.WithPrimaryPrivateIPAddressDynamic()
.WithoutPrimaryPublicIPAddress()
.WithSpecificLinuxImageVersion(new ImageReference(new ImageReferenceInner(
publisher: "nvidia",
offer: "ngc_azure_17_11",
sku: "ngc-base-version-20-10-1",
version: "20.10.1"
)))
.WithRootUsername(userName)
.WithRootPassword(password)
.WithSize(VirtualMachineSizeTypes.StandardNC6sV3)
.WithPlan(new PurchasePlan("nvidia", "ngc-base-version-20-10-1", "ngc_azure_17_11"))
.CreateAsync();
The version can be found in the UI:
It's also possible to get all the image's details via CLI:
Get-AzVMImageOffer -Location "West Europe" -PublisherName nvidia
A fuller guide can be found here

Playing an HDHomeRun stream on a Tizen.NET Xamarin App

I'm trying to play a HDHomeRun Connect Video source from a url in the following format: http://x.x.x.x:xxxx/auto/v4.1. This video source is an MPEG2 video encoding and AC3 audio encoding.
I've tried using the Samsung Tizen.TV .NET sample with the following source but the video never plays.
_player = new Tizen.Multimedia.Player();
var mediaSource = new Multimedia.MediaUriSource(uri);
_player.SetSource(mediaSource);
var display = new Multimedia.Display(Window.Instance);
_player.Display = display;
await _player.PrepareAsync();
The player state gets stuck in preparing, and the await _player.PrepareAsync() call never finishes. It is worth noting that I'm using the Tizen Samsung TV Emulator. Do I need to transcode the stream from the HDHomeRun to be playable? Are there any other measures I might be missing for the Video to play?
Ultimately, the Display property of the player wasn't being set correctly. The property that worked for me (found from investigating the JuvoPlayer code was this:
var display = new Multimedia.Display(((FormsApplication)Forms.Context).MainWindow);
_player.Display = display;
When you are to develop a Tizen .NET application, please be aware of which UI framework your project is targetted for among 3 different types: Xamarin.Forms, (pure) ElmSharp, and Tizen.NUI.
Unless your project is based on the Tizen.NUI framework, you shouldn't use Tizen.NUI.Window.Instance and types in Tizen.NUI namespace in any case. Instead, you will have to use types of ElmSharp or Xamarin.Forms.Platform.Tizen namespace for platform-specific code in your application.
Since the internal implementation of Xamarin.Forms for Tizen is based on ElmSharp, FormsApplication.MainWindow will return a ElmSharp.Window instance which can be used to instantiate a Tizen.Multimedia.Display object. That's why the code in your answer worked.

Xamarin DisplayAlert not work on android live player

I use DisplayAlert in my project for displaying content of page, it works on UWP(universal Windows) local machine. But when i try to use this application on Xamarin live player on Android my button does not want work.
my code in button_Clicked:
WebClient myWebClient = new WebClient();
Page p = new Page();
byte[] myDataBuffer = myWebClient.DownloadData(URL);
var download = Encoding.ASCII.GetString(myDataBuffer);
p.DisplayAlert("page:", download, "close");
Difrent button without DisplayAlert works well in Live player.
The live player has many limitations. It's better to test your app on an emulator or test it on a real device through a USB-cable.
And I think you should just call this.DisplayAlert("page:", download, "close") instead of p.DisplayAlert("page:", download, "close");

C# wpf how to stream webcam to ip address (possibly with Vlc)

I need to stream a webcam to an ip address.
After days of googling I decided that the easiest way was to embed Vlc.
That said I am also still open to other solutions.
Step1 - OK!: I can see my webcam in a form by using that code:
vlcPlayer.MediaPlayer.VlcLibDirectory = new DirectoryInfo(#"c:\Program Files (x86)\VideoLAN\VLC\");
vlcPlayer.MediaPlayer.EndInit();
vlcPlayer.MediaPlayer.Play(new Uri(#"dshow://");
Step2 - OK!: Now trying to make a step forward and using this tutorial I can send a video locally 127.0.0.1:5004 using 2 instances of Vlc: one to transmit and one to receive.
Step 3 - NOT OK: it should seem simple to configure vlc for changing the source from file to webcam and to transmit it via ip.
So what I do is to operate as before only changing the source:
1. Menu "Media" --> Stream. That opens the "open media" window.
Here I click the tab capture device --> video device name --> I choose "integrated webcam"
Then all the rest is as before. But nothing happens. The receiver is black with nothing inside. Also If I try to save the flow from the receiver I only get a few bytes.
The afore mentioned settings for the transmitter are the following:
Capture device tab --> integrated webcam. Then the stream button --> the window opens correctly with dshow:\ --> next --> new destination RTP,MPEG transport stream ---> add button --> address = 127.0.0.1 port = 5004 StreamNAme=test
So the strange is that when I stream a file with whatever name from the transmitter, it immediately is recognized by the receiver. Instead try as I might, nothing happens when the webcam is the source.
That being said the problem above is not crucial to the solution.
What I care for is not how to use vlc stand alone but how to use it from my wpf application in order to send the webcam stream.
Thanks for any help
Patrick
I believe this sample should help you achieve your goal:
static void Main()
{
var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
// Default installation path of VideoLAN.LibVLC.Windows
var libDirectory =
new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
using (var mediaPlayer = new Vlc.DotNet.Core.VlcMediaPlayer(libDirectory))
{
var mediaOptions = new[]
{
":sout=#rtp{sdp=rtsp://127.0.0.1:554/}",
":sout-keep"
};
mediaPlayer.SetMedia(new Uri("http://hls1.addictradio.net/addictrock_aac_hls/playlist.m3u8"),
mediaOptions);
mediaPlayer.Play();
Console.WriteLine("Streaming on rtsp://127.0.0.1:554/");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
You will need 2 nuget packages: Vlc.DotNet (C# wrapper) and VideoLAN.LibVLC.Windows (LibVLC library for Windows).

Retrieving AVPlayerItem from Gallery Asset

I'm trying to play a video using the AVPlayer and an AVPlayerItem.
Im using following code:
asset = AVAsset.FromUrl(new NSUrl(GalleryURL));
playerItem = new AVPlayerItem(asset);
playerItem.AddObserver(this, (NSString)"status", NSKeyValueObservingOptions.OldNew, IntPtr.Zero);
player = new AVPlayer(playerItem);
the property GalleryURL is one of the following:
1.) When saving a video to the gallery, i get this url from the ALAssetsLibrary instance call: WriteVideoToSavedPhotosAlbum(url, (galleryPath, error) => { ... });
where "galleryPath" is something like this:
file:///var/mobile/Containers/Data/Application/0D510365-4A63-425B-840C-A4E18BD870A8/Documents/...
this works fine, I can create the AVAsset and retrieve the AVPlayerItemStatus, especially the status "ReadyToPlay", via the added Observer.
2.) However when I retrieve a Video from the gallery, the url looks different:
assets-library://asset/asset.MOV?id=EB9FC214...
and in this case I'm not able to retrieve a working AVAsset
How can I get part 2 to create a working AVAsset, which I can use for video playback? I believe this works in iOS versions prior to iOS 11.
Landu Lu - MSFT helped me to find the answer:
He told me that there are 2 paths that I receive from the UIImagePickerController:
The asset-library path could not be used, maybe I have to remove the "assets-library:" part? but the path beginning with "file://" could be used. The problem of the plugin was, that the start of the url was cut off, there was no "file://" at the beginning. I manually added this string and it works! Thanks alot!

Categories