This commit is contained in:
Miguel de Icaza 2010-10-31 23:43:12 -04:00
Родитель ee11a8e380
Коммит 894c6cb2e3
8 изменённых файлов: 234 добавлений и 45 удалений

Просмотреть файл

@ -69,7 +69,7 @@
<Reference Include="monotouch" />
<Reference Include="GANTracker, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\monotouch-libs\GoogleAnalytics\GANTracker.dll</HintPath>
<HintPath>GANTracker.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -20,6 +20,8 @@ namespace GoogleAnalytics
{
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
Console.WriteLine ("Foo");
// Replace with your account information.
var account = "UA-000000-1";
int time = 10;
@ -27,7 +29,7 @@ namespace GoogleAnalytics
var tracker = GoogleAnalytics.GANTracker.SharedTracker;
tracker.StartTracker (account, time, null);
var label = new UILabel (new RectangleF (10, 10, 300, 20));
var label = new UILabel (new RectangleF (10, 90, 300, 20));
NSError error;
if (tracker.TrackPageView ("/app_entry_point", out error))

Просмотреть файл

@ -7,8 +7,10 @@
// MIT X11
//
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Net;
@ -31,7 +33,9 @@ namespace StreamingAudio
}
StreamingPlayback player = null;
QueueStream queueStream;
bool paused;
bool saveCopy;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
@ -49,6 +53,7 @@ namespace StreamingAudio
return true;
}
// Action hooked up on Interface Builder
partial void playControlClicked (UIButton sender)
{
paused = !paused;
@ -66,6 +71,7 @@ namespace StreamingAudio
button.SetTitle (title, UIControlState.Selected);
}
// Action hooked up on Interface Builder
partial void volumeSet (UISlider sender)
{
if (player == null)
@ -74,14 +80,35 @@ namespace StreamingAudio
player.Volume = sender.Value;
}
partial void startPlayback (UIButton sender)
void PreparePlayback ()
{
status.Text = "Starting HTTP request";
// The following line prevents the audio from stopping
// when the device autolocks.
AudioSession.Category = AudioSessionCategory.MediaPlayback;
AudioSession.RoutingOverride = AudioSessionRoutingOverride.Speaker;
button.TitleLabel.Text = "Pause";
button.TitleLabel.Text = "Pause";
}
// Action hooked up on Interface Builder
partial void startPlayback (UIButton sender)
{
saveCopy = false;
StartPlayback ();
}
// Action hooked up on Interface Builder
partial void startPlaybackAndSave (UIButton sender)
{
saveCopy = true;
StartPlayback ();
}
void StartPlayback ()
{
PreparePlayback ();
try {
var request = (HttpWebRequest) WebRequest.Create (entry.Text);
request.BeginGetResponse (StreamDownloaded, request);
@ -89,14 +116,15 @@ namespace StreamingAudio
status.Text = "Error: " + e.ToString ();
}
}
void StreamDownloaded (IAsyncResult result)
{
var request = result.AsyncState as HttpWebRequest;
bool pushed = false;
try {
var response = request.EndGetResponse (result);
var stream = response.GetResponseStream ();
var responseStream = response.GetResponseStream ();
Stream inputStream;
var buffer = new byte [8192];
int l = 0, n;
@ -105,17 +133,18 @@ namespace StreamingAudio
});
pushed = true;
// The following line prevents the audio from stopping
// when the device autolocks.
AudioSession.Category = AudioSessionCategory.MediaPlayback;
if (saveCopy)
inputStream = MakeQueueStream (responseStream);
else
inputStream = responseStream;
//
// Create StreamingPlayer, the using statement will automatically
// force the resources to be disposed and the playback to stop.
//
using (player = new StreamingPlayback ()){
while ((n = stream.Read (buffer, 0, buffer.Length)) != 0){
while ((n = inputStream.Read (buffer, 0, buffer.Length)) != 0){
l += n;
player.ParseBytes (buffer, n, false);
@ -146,5 +175,26 @@ namespace StreamingAudio
status.Text = "Finished playback";
}
}
//
// Launches a thread that reads the network stream
// and queues it for use by our audio thread
//
Stream MakeQueueStream (Stream networkStream)
{
queueStream = new QueueStream (Environment.GetFolderPath (Environment.SpecialFolder.Personal) + "copy.mp3");
var t = new Thread ((x) => {
var tbuf = new byte [8192];
int count;
while ((count = networkStream.Read (tbuf, 0, tbuf.Length)) != 0){
queueStream.Push (tbuf, 0, count);
}
});
t.Start ();
return queueStream;
}
}
}

Просмотреть файл

@ -3,18 +3,18 @@
<data>
<int key="IBDocument.SystemTarget">768</int>
<string key="IBDocument.SystemVersion">10C540</string>
<string key="IBDocument.InterfaceBuilderVersion">740</string>
<string key="IBDocument.InterfaceBuilderVersion">761</string>
<string key="IBDocument.AppKitVersion">1038.25</string>
<string key="IBDocument.HIToolboxVersion">458.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">62</string>
<string key="NS.object.0">84</string>
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="2"/>
<integer value="50"/>
<integer value="21"/>
<integer value="29"/>
<integer value="2"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -33,11 +33,15 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBProxyObject" id="841351856">
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBProxyObject" id="587066532">
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUICustomObject" id="987256611">
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUICustomObject" id="987256611"/>
<object class="IBUIWindow" id="380026005">
<reference key="NSNextResponder"/>
<int key="NSvFlags">1316</int>
@ -51,9 +55,15 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUINavigationController" id="732511712">
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
<int key="interfaceOrientation">1</int>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIHorizontal">NO</bool>
<object class="IBUINavigationBar" key="IBUINavigationBar" id="753096672">
<nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
@ -61,6 +71,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIMultipleTouchEnabled">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="NSMutableArray" key="IBUIViewControllers">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -78,6 +89,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">Select URL of MP3 file to stream:</string>
<object class="NSColor" key="IBUITextColor" id="79086812">
<int key="NSColorSpace">1</int>
@ -90,10 +102,11 @@
<object class="IBUIButton" id="315123057">
<reference key="NSNextResponder" ref="812770021"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{90, 102}, {140, 37}}</string>
<string key="NSFrame">{{52, 111}, {225, 37}}</string>
<reference key="NSSuperview" ref="812770021"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<object class="NSFont" key="IBUIFont" id="120824268">
@ -102,7 +115,7 @@
<int key="NSfFlags">16</int>
</object>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">Start Playback</string>
<string key="IBUINormalTitle">Stream and Play</string>
<object class="NSColor" key="IBUIHighlightedTitleColor" id="592136135">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
@ -123,6 +136,7 @@
<reference key="NSSuperview" ref="812770021"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentVerticalAlignment">0</int>
<string key="IBUIText"/>
<int key="IBUIBorderStyle">3</int>
@ -141,7 +155,9 @@
<bool key="IBUIClearsOnBeginEditing">YES</bool>
<bool key="IBUIAdjustsFontSizeToFit">YES</bool>
<float key="IBUIMinimumFontSize">17</float>
<object class="IBUITextInputTraits" key="IBUITextInputTraits"/>
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
</object>
<object class="IBUILabel" id="502023951">
<reference key="NSNextResponder" ref="812770021"/>
@ -151,6 +167,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">Label</string>
<reference key="IBUITextColor" ref="79086812"/>
<nil key="IBUIHighlightedColor"/>
@ -160,6 +177,25 @@
<int key="IBUINumberOfLines">13</int>
<int key="IBUILineBreakMode">0</int>
</object>
<object class="IBUIButton" id="768533046">
<reference key="NSNextResponder" ref="812770021"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{52, 163}, {225, 37}}</string>
<reference key="NSSuperview" ref="812770021"/>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<reference key="IBUIFont" ref="120824268"/>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">Stream, Save and Play</string>
<reference key="IBUIHighlightedTitleColor" ref="592136135"/>
<object class="NSColor" key="IBUINormalTitleColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes>
</object>
<reference key="IBUINormalTitleShadowColor" ref="780032884"/>
</object>
</object>
<string key="NSFrameSize">{320, 416}</string>
<reference key="NSSuperview"/>
@ -169,12 +205,19 @@
<reference key="NSCustomColorSpace" ref="568940393"/>
</object>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUINavigationItem" key="IBUINavigationItem" id="449771860">
<reference key="IBUINavigationBar"/>
<string key="IBUITitle">Stream MP3 File</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<reference key="IBUIParentViewController" ref="732511712"/>
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
<int key="interfaceOrientation">1</int>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIHorizontal">NO</bool>
</object>
</object>
</object>
@ -192,6 +235,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIMultipleTouchEnabled">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<float key="IBUIValue">1</float>
@ -204,6 +248,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">Download Progress:</string>
<reference key="IBUITextColor" ref="79086812"/>
<nil key="IBUIHighlightedColor"/>
@ -218,6 +263,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">Volume:</string>
<reference key="IBUITextColor" ref="79086812"/>
<nil key="IBUIHighlightedColor"/>
@ -232,6 +278,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIMultipleTouchEnabled">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUILabel" id="343504676">
<reference key="NSNextResponder" ref="983264090"/>
@ -241,6 +288,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">Streaming audio:</string>
<reference key="IBUITextColor" ref="79086812"/>
<nil key="IBUIHighlightedColor"/>
@ -255,6 +303,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">Playback Progress:</string>
<reference key="IBUITextColor" ref="79086812"/>
<nil key="IBUIHighlightedColor"/>
@ -269,6 +318,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIMultipleTouchEnabled">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIButton" id="412927193">
<reference key="NSNextResponder" ref="983264090"/>
@ -277,6 +327,7 @@
<reference key="NSSuperview" ref="983264090"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<reference key="IBUIFont" ref="120824268"/>
@ -298,8 +349,14 @@
<reference key="NSCustomColorSpace" ref="568940393"/>
</object>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
<int key="interfaceOrientation">1</int>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIHorizontal">NO</bool>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
@ -412,6 +469,15 @@
</object>
<int key="connectionID">55</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">startPlaybackAndSave:</string>
<reference key="source" ref="768533046"/>
<reference key="destination" ref="987256611"/>
<int key="IBEventType">1</int>
</object>
<int key="connectionID">57</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@ -484,8 +550,9 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="630004556"/>
<reference ref="122687021"/>
<reference ref="315123057"/>
<reference ref="502023951"/>
<reference ref="768533046"/>
<reference ref="315123057"/>
</object>
<reference key="parent" ref="138859781"/>
</object>
@ -574,6 +641,11 @@
<reference key="object" ref="412927193"/>
<reference key="parent" ref="983264090"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">56</int>
<reference key="object" ref="768533046"/>
<reference key="parent" ref="812770021"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@ -609,6 +681,7 @@
<string>49.IBPluginDependency</string>
<string>50.IBPluginDependency</string>
<string>51.IBPluginDependency</string>
<string>56.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -647,6 +720,7 @@
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@ -665,7 +739,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">55</int>
<int key="maxID">57</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -678,6 +752,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>playControlClicked:</string>
<string>startPlayback:</string>
<string>startPlaybackAndSave:</string>
<string>volumeSet:</string>
</object>
<object class="NSMutableArray" key="dict.values">
@ -685,6 +760,7 @@
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
@ -722,6 +798,7 @@
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
<integer value="768" key="NS.object.0"/>
@ -733,6 +810,6 @@
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<nil key="IBDocument.LastKnownRelativeProjectPath"/>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">3.1</string>
<string key="IBCocoaTouchPluginVersion">84</string>
</data>
</archive>

57
StreamingAudio/MainWindow.xib.designer.cs сгенерированный
Просмотреть файл

@ -15,6 +15,24 @@ namespace StreamingAudio {
[MonoTouch.Foundation.Register("AppDelegate")]
public partial class AppDelegate {
private MonoTouch.UIKit.UIWindow __mt_window;
private MonoTouch.UIKit.UINavigationController __mt_viewController;
private MonoTouch.UIKit.UITextField __mt_entry;
private MonoTouch.UIKit.UIViewController __mt_playController;
private MonoTouch.UIKit.UISlider __mt_volume;
private MonoTouch.UIKit.UIProgressView __mt_progress;
private MonoTouch.UIKit.UILabel __mt_status;
private MonoTouch.UIKit.UIButton __mt_button;
private MonoTouch.UIKit.UIProgressView __mt_playbackProgress;
#pragma warning disable 0169
[MonoTouch.Foundation.Export("startPlayback:")]
partial void startPlayback (MonoTouch.UIKit.UIButton sender);
@ -25,12 +43,17 @@ namespace StreamingAudio {
[MonoTouch.Foundation.Export("volumeSet:")]
partial void volumeSet (MonoTouch.UIKit.UISlider sender);
[MonoTouch.Foundation.Export("startPlaybackAndSave:")]
partial void startPlaybackAndSave (MonoTouch.UIKit.UIButton sender);
[MonoTouch.Foundation.Connect("window")]
private MonoTouch.UIKit.UIWindow window {
get {
return ((MonoTouch.UIKit.UIWindow)(this.GetNativeField("window")));
this.__mt_window = ((MonoTouch.UIKit.UIWindow)(this.GetNativeField("window")));
return this.__mt_window;
}
set {
this.__mt_window = value;
this.SetNativeField("window", value);
}
}
@ -38,9 +61,11 @@ namespace StreamingAudio {
[MonoTouch.Foundation.Connect("viewController")]
private MonoTouch.UIKit.UINavigationController viewController {
get {
return ((MonoTouch.UIKit.UINavigationController)(this.GetNativeField("viewController")));
this.__mt_viewController = ((MonoTouch.UIKit.UINavigationController)(this.GetNativeField("viewController")));
return this.__mt_viewController;
}
set {
this.__mt_viewController = value;
this.SetNativeField("viewController", value);
}
}
@ -48,9 +73,11 @@ namespace StreamingAudio {
[MonoTouch.Foundation.Connect("entry")]
private MonoTouch.UIKit.UITextField entry {
get {
return ((MonoTouch.UIKit.UITextField)(this.GetNativeField("entry")));
this.__mt_entry = ((MonoTouch.UIKit.UITextField)(this.GetNativeField("entry")));
return this.__mt_entry;
}
set {
this.__mt_entry = value;
this.SetNativeField("entry", value);
}
}
@ -58,9 +85,11 @@ namespace StreamingAudio {
[MonoTouch.Foundation.Connect("playController")]
private MonoTouch.UIKit.UIViewController playController {
get {
return ((MonoTouch.UIKit.UIViewController)(this.GetNativeField("playController")));
this.__mt_playController = ((MonoTouch.UIKit.UIViewController)(this.GetNativeField("playController")));
return this.__mt_playController;
}
set {
this.__mt_playController = value;
this.SetNativeField("playController", value);
}
}
@ -68,9 +97,11 @@ namespace StreamingAudio {
[MonoTouch.Foundation.Connect("volume")]
private MonoTouch.UIKit.UISlider volume {
get {
return ((MonoTouch.UIKit.UISlider)(this.GetNativeField("volume")));
this.__mt_volume = ((MonoTouch.UIKit.UISlider)(this.GetNativeField("volume")));
return this.__mt_volume;
}
set {
this.__mt_volume = value;
this.SetNativeField("volume", value);
}
}
@ -78,9 +109,11 @@ namespace StreamingAudio {
[MonoTouch.Foundation.Connect("progress")]
private MonoTouch.UIKit.UIProgressView progress {
get {
return ((MonoTouch.UIKit.UIProgressView)(this.GetNativeField("progress")));
this.__mt_progress = ((MonoTouch.UIKit.UIProgressView)(this.GetNativeField("progress")));
return this.__mt_progress;
}
set {
this.__mt_progress = value;
this.SetNativeField("progress", value);
}
}
@ -88,9 +121,11 @@ namespace StreamingAudio {
[MonoTouch.Foundation.Connect("status")]
private MonoTouch.UIKit.UILabel status {
get {
return ((MonoTouch.UIKit.UILabel)(this.GetNativeField("status")));
this.__mt_status = ((MonoTouch.UIKit.UILabel)(this.GetNativeField("status")));
return this.__mt_status;
}
set {
this.__mt_status = value;
this.SetNativeField("status", value);
}
}
@ -98,9 +133,11 @@ namespace StreamingAudio {
[MonoTouch.Foundation.Connect("button")]
private MonoTouch.UIKit.UIButton button {
get {
return ((MonoTouch.UIKit.UIButton)(this.GetNativeField("button")));
this.__mt_button = ((MonoTouch.UIKit.UIButton)(this.GetNativeField("button")));
return this.__mt_button;
}
set {
this.__mt_button = value;
this.SetNativeField("button", value);
}
}
@ -108,9 +145,11 @@ namespace StreamingAudio {
[MonoTouch.Foundation.Connect("playbackProgress")]
private MonoTouch.UIKit.UIProgressView playbackProgress {
get {
return ((MonoTouch.UIKit.UIProgressView)(this.GetNativeField("playbackProgress")));
this.__mt_playbackProgress = ((MonoTouch.UIKit.UIProgressView)(this.GetNativeField("playbackProgress")));
return this.__mt_playbackProgress;
}
set {
this.__mt_playbackProgress = value;
this.SetNativeField("playbackProgress", value);
}
}

Просмотреть файл

@ -4,11 +4,14 @@ 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.
This code does not attempt to buffer beyond the four built-in buffers
that are created at startup. It will happily stall until the audio
pipeline releases one of the audio buffers.
There are two samples:
A better implementation would save the data to disk as well.
* One plays as it streams, and does not attempt to buffer
more than the audio buffers that are used for AudioToolbox.
* The second sample shows how to save a copy of the data as it
is being downloaded (for example, a podcasting application
would stream audio and retain a copy).
To use this you need either MonoTouch 1.4 or to download the preview
monotouch.dll from:

Просмотреть файл

@ -11,8 +11,8 @@
<RootNamespace>StreamingAudio</RootNamespace>
<MainNibFile>MainWindow.xib</MainNibFile>
<AssemblyName>StreamingAudio</AssemblyName>
<MtouchSdkVersion>3.0</MtouchSdkVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<MtouchMinimumOS>3.0</MtouchMinimumOS>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
@ -22,10 +22,11 @@
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<MtouchLink>None</MtouchLink>
<MtouchDebug>True</MtouchDebug>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<MtouchSdkVersion>3.2</MtouchSdkVersion>
<MtouchI18n />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
@ -33,10 +34,10 @@
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<MtouchLink>None</MtouchLink>
<MtouchDebug>False</MtouchDebug>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<MtouchSdkVersion>3.0</MtouchSdkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
@ -46,10 +47,10 @@
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<CodesignKey>iPhone Developer</CodesignKey>
<CodesignKey>iPhone Developer: Miguel de Icaza (6YW2BSTNRQ)</CodesignKey>
<MtouchDebug>True</MtouchDebug>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<MtouchSdkVersion>3.0</MtouchSdkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
@ -57,10 +58,10 @@
<OutputPath>bin\iPhone\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<CodesignKey>iPhone Developer</CodesignKey>
<CodesignKey>iPhone Developer: Miguel de Icaza (6YW2BSTNRQ)</CodesignKey>
<MtouchDebug>False</MtouchDebug>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<MtouchSdkVersion>3.0</MtouchSdkVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@ -74,6 +75,7 @@
</Compile>
<Compile Include="Main.cs" />
<Compile Include="StreamingPlayback.cs" />
<Compile Include="Storage.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="MainWindow.xib" />

Просмотреть файл

@ -187,13 +187,29 @@ namespace StreamingAudio
}
AudioQueue.FillAudioData (currentBuffer.Buffer, currentBuffer.CurrentOffset, args.InputData, (int)pd.StartOffset, pd.DataByteSize);
#if false
// Set new offset for this packet
pd.StartOffset = currentBuffer.CurrentOffset;
// Add the packet to our Buffer
currentBuffer.PacketDescriptions.Add (pd);
// Add the Size so that we know how much is in the buffer
currentBuffer.CurrentOffset += pd.DataByteSize;
#else
// Fill out the packet description
pdesc [packetsFilled] = pd;
pdesc [packetsFilled].StartOffset = bytesFilled;
bytesFilled += packetSize;
packetsFilled++;
var t = OutputQueue.CurrentTime;
Console.WriteLine ("Time: {0}", t);
// If we filled out all of our packet descriptions, enqueue the buffer
if (pdesc.Length == packetsFilled){
EnqueueBuffer ();
WaitForBuffer ();
}
#endif
}
if (currentByteCount == fileStream.DataByteCount)