Xamarin Tvos Play Streaming Media
- Streaming Audio This sample illustrates how to use AudioToolbox's AudioFileStream to parse an audio stream progressively and play the audio back. The audio is a creative commons MP3 file that is downloaded from a website using Mono's HTTP stack.
- LibVLC is a modular multimedia framework that can render video and output audio as well as encode and stream. A Xamarin Forms control to render the native video player on every platform. LibVLC is a modular multimedia framework that can render video and output audio as well as encode and stream.
I have a Xamarin app that works using MediaManager and plays video content as needed, however I need to also play RTP/RTSP streams not just Http streams. I have tried and it dosn't seem to work on IOS/iPad (required device), has anyone seen this working?
The github repo says it should work but I can't seem to get it going.
Xamarin.iOS – Adding Audio. You can play audio or video from media files stored in your application’s resources (raw resources), from standalone files in the filesystem, or from a data stream arriving over a network connection.
1 Answer
Plugin.MediaManager
uses the native AVPlayer
and thus RTMP/RTSP is not supported.
Apple does not natively support RTMP (Real Time Messaging Protocol) in their OSs (iOS, tvOS, macOS). HTTP Live Streaming (HLS) is natively supported (RFC8216).
Also see: https://stackoverflow.com/a/47596246/4984832
Send live and on‐demand audio and video to iPhone, iPad, Mac, Apple TV, and PC with HTTP Live Streaming (HLS) technology from Apple.
SushiHangoverSushiHangoverNot the answer you're looking for? Browse other questions tagged xamarinxamarin.formsxamarin.ios or ask your own question.
This is a guest post from Adam Fisher. Adam is the founder of Octane Software, focused on the creation of consumer Internet products. You can find Adam on Twitter at @adamgfisher and on Github at @adamfisher. Today we’ll take a look at Adam’s Xamarin.Forms Video Player component.
Delivering an interactive and engaging experience is critical to standing out in today’s massive app marketplace. Using video in your mobile apps offers an excellent way to engage your users and keep them in your app longer.
The Xamarin.Forms Video Player minimizes the complexity of video playback across Android, iOS, and Windows environments. The player accomplishes this by unifying several operations (Play, Stop, Seek, etc.) as well as events (playing, paused, completed, etc.) through a standard XAML control appropriately named, VideoPlayer
, with the ability to play local files and embedded resources or HTTP(S)-based streamed files from the web.
The goal of any Xamarin Forms UI control is to provide a cross-platform unified interface to a platform’s native controls. As such, the Xamarin.Forms Video Player manages the AVPlayer
on iOS, the MediaPlayer
on Android, and the MediaElement
on Windows platforms. This approach ensures your users will have a familiar experience with video playback since it makes use of the video player they have probably already been using.
Getting Started
You can incorporate the Xamarin.Forms Video Player into your Xamarin.Forms project by installing the trial version of the package from NuGet, or by using the NuGet Package Manager within your chosen IDE. We’ll be using Visual Studio 2017 and the Xamarin.Forms .NET Standard template for this example. You’ll need to install the package in every platform-specific project (iOS and Android for example), as well as the project containing your Xamarin.Forms pages.
Insert the following initialization call after the Xamarin.Forms initialization call, depending on the platform(s) you are targeting, as shown below:
Android (MainActivity.cs
)
You also have the ability to play media files embedded in your application assembly, but the player needs a little help differentiating it from a local file path. The file can be in any project referenced in your solution, as long as the build action of the video is marked as an embedded resource.
You can either assign it in XAML by including and using the VideoResource
markup extension (not included in the plugin), or in code like this:
myPlayer.Source=VideoSource.FromResource('MyEmbeddedFile.mp4'); |
Understanding Video State
Xamarin Tvos Play Streaming Media System
Invoking myPlayer.Play();
won’t work if you try to invoke it directly. The native video player of each platform each has its own unique behavior. In general, you can’t play a video file until its data stream has been opened for playback. By default, the plugin is set to automatically play the media file as soon as it is passed to the Source
property. You can change this behavior by setting the AutoPlay
property to false
.
If you want fine grained control during various parts of the lifecycle, you can hook into the various playback events exposed by the player. Although you have access to individual playback events, you can also hook into the PlayerStateChanged
event if you wish to handle multiple events inside a single event handler.
2 4 6 8 10 12 14 16 18 20 22 24 | ... { { { { videoPlayer.Play();// The video source is now ready for playback so you can call sender.Play() manually if you wish. casePlayerState.Completed: Navigation.PopAsync();// Go back to the previous page once the video completes. casePlayerState.Error: DisplayAlert('Error Playing Video','We're sorry but something is wrong with this video.','OK'); } } |
Setting the TimeElapsedInterval
to a non-zero value will fire at the specified number of seconds during playback, allowing you to perform operations during various points in the playback timeline.
- Can I play video from streaming sources like RTSP/RTCP/RTP? Yes, but it depends on the platforms you plan to target. Each platform has a predefined set of supported codecs, so you’ll want to refer to the native platform video player documentation mentioned in the opening section of this article (iOS’s
AVPlayer
, Android’sMediaPlayer
, and the WindowsMediaElement
) to determine what codecs are supported. - Can I stream YouTube/Vimeo/(Other Video Site) Videos? Yes, as long as you have the direct URL to a video file (typically ending with a file extension like .mp4). There are several XAML markup extensions available for retrieving the raw video URLs from services like YouTube and Vimeo. Just note that the only officially supported of retrieving video URLs is through each provider’s API.
- Can I play multiple videos on a single page? This is highly discouraged, as some platforms (looking at you Android emulator) are resource constrained and consistently crash when more than one video player is loaded per page. With such a small screen, the user’s attention is already limited in what they can see. It’s best to keep a reference to a single instance and then move it around the page as necessary, swapping out image thumbnails for the player (it’s just another Xamarin.Forms.View, after all).
Summary
Cross-platform video can be a powerful addition to your mobile application. The Xamarin.Forms Video Player NuGet package is ready to go with a single line of drop-in code, as we detailed in the first section. You can get a more in-depth overview of the available customizations and configuration options in the Getting Started guide, or by watching a video tutorial to set up your project, starting from an empty Xamarin.Forms solution template to playing a video. The Chill Player example application on GitHub is also a great example, showing off full-screen video pages, custom video controls, playlist queues, and playing YouTube or Vimeo videos.
Happy coding!