Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dependency service to stream in iOS and Android
- Add IStreaming interface - Implement DependencyInjection in iOS - Implement DependencyInjection in Android
- Loading branch information
1 parent
7c53084
commit f304be0
Showing
10 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,6 +1,8 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.ilanolkies.StreamingExample"> | <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.ilanolkies.StreamingExample"> | ||
<uses-sdk android:minSdkVersion="15" /> | <uses-sdk android:minSdkVersion="15" /> | ||
<application android:label="StreamingExample"> | <uses-permission android:name="android.permission.INTERNET" /> | ||
</application> | <uses-permission android:name="android.permission.WAKE_LOCK" /> | ||
</manifest> | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<application android:label="StreamingExample"></application> | |||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
using StreamingExample.Droid; | |||
using Xamarin.Forms; | |||
using Android.Media; | |||
|
|||
[assembly: Dependency(typeof(StreamingService))] | |||
namespace StreamingExample.Droid | |||
{ | |||
public class StreamingService : IStreaming | |||
{ | |||
MediaPlayer player; | |||
string dataSource = "rtsp://your.domain.com/stream.stream"; | |||
|
|||
bool isPrepared; | |||
|
|||
public void Play() | |||
{ | |||
if (!isPrepared) | |||
{ | |||
if (player == null) | |||
player = new MediaPlayer(); | |||
else | |||
player.Reset(); | |||
|
|||
player.SetDataSource(dataSource); | |||
player.PrepareAsync(); | |||
} | |||
|
|||
player.Prepared += (sender, args) => | |||
{ | |||
player.Start(); | |||
isPrepared = true; | |||
}; | |||
} | |||
|
|||
public void Pause() | |||
{ | |||
player.Pause(); | |||
} | |||
|
|||
public void Stop() | |||
{ | |||
player.Stop(); | |||
isPrepared = false; | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,6 +1,11 @@ | |||
# XamarinRadioStreamingExample | # XamarinRadioStreamingExample | ||
## Setup | |||
On _/iOS_ | |||
Set your streaming domain in _StreamingService.cs_. Change `dataSource`. | |||
Allow transport in _Info.plist_ secure domains (change your.domain.com). | |||
|
|
||
On Android | |||
Set your streaming domain in _StreamingService.cs_. Change `dataSource`. | |||
|
|
||
## Resources | ## Resources | ||
- Icons: [FlatIcon](https://www.flaticon.com/packs/music) | - Icons: [FlatIcon](https://www.flaticon.com/packs/music) | ||
- Streaming: [Radio Zonica](http://radiozonica.com.ar) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
using System.Threading.Tasks; | |||
|
|||
namespace StreamingExample | |||
{ | |||
public interface IStreaming | |||
{ | |||
void Play(); | |||
void Pause(); | |||
void Stop(); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
using StreamingExample.iOS; | |||
using Xamarin.Forms; | |||
using AVFoundation; | |||
using Foundation; | |||
|
|||
[assembly: Dependency(typeof(StreamingService))] | |||
namespace StreamingExample.iOS | |||
{ | |||
public class StreamingService : IStreaming | |||
{ | |||
AVPlayer player; | |||
bool isPrepared; | |||
string dataSource = "http://your.domain.com/stream"; | |||
|
|||
public void Play() | |||
{ | |||
AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback); | |||
if (!isPrepared || player == null) | |||
player = AVPlayer.FromUrl(NSUrl.FromString(dataSource)); | |||
|
|||
isPrepared = true; | |||
player.Play(); | |||
} | |||
|
|||
public void Pause() | |||
{ | |||
player.Pause(); | |||
} | |||
|
|||
public void Stop() | |||
{ | |||
player.Dispose(); | |||
isPrepared = false; | |||
} | |||
} | |||
} |