-
-
Save martinbowling/1982693 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using MonoTouch.UIKit; | |
using System.Drawing; | |
using MonoTouch.AudioToolbox; | |
namespace GoogleMusic | |
{ | |
public class LevelMeter : UIView | |
{ | |
public AudioQueueLevelMeterState[] AudioLevelState {get;set;} | |
public LevelMeter (RectangleF rect ) :base (rect) | |
{ | |
Padding = 10; | |
this.Alpha = .8f; | |
} | |
public float Padding {get;set;} | |
public override void Draw (RectangleF rect) | |
{ | |
if(AudioLevelState == null || AudioLevelState.Length == 0) | |
{ | |
base.Draw(rect); | |
return; | |
} | |
var width = (this.Frame.Width - (Padding * 2))/2;// AudioLevelState.Length; | |
var height = (this.Frame.Height - (Padding * 2)); | |
var curX = Padding; | |
var curY = Padding + height; | |
UIColor.White.SetColor(); | |
var context = UIGraphics.GetCurrentContext(); | |
context.ClearRect(this.Bounds); | |
context.SetFillColorWithColor(UIColor.Green.CGColor); | |
int index = 0; | |
foreach(var level in AudioLevelState) | |
{ | |
if(index > 1) | |
continue; | |
var power = level.AveragePower; | |
if(power > 1) | |
power = 1; | |
else if(power < 0 ) | |
power = 0; | |
context.FillRect(new RectangleF(curX,curY,(width - 2),(height -2) * power * -1)); | |
curX += width; | |
index ++; | |
} | |
//context.FillRect(new RectangleF(curX,curY,(width - Padding) * AudioLevelState[0].AveragePower,height -2)); | |
//curY += height; | |
//context.FillRect(new RectangleF(curX,curY,(width - Padding) * AudioLevelState[1].AveragePower,height -2)); | |
context.Flush(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment