- Home /
U3DXT AVAudioPlayer
Hi, I'm trying to use the AVAudioPlayer class of U3DXT but after creating a new instance of the AVAudioPlayer and calling Play() I get the following error:
U3DXTException: Cached object (null) is invalid at U3DXT.iOS.Native.Internals._CallbackCache._ThrowException (System.String str) [0x00000] in :0 at (wrapper native-to-managed) U3DXT.iOS.Native.Internals._CallbackCache:_ThrowException (intptr) at U3DXT.iOS.Native.AVFoundation.AVAudioPlayer.Play ()
The code that causes this error is as follows :
#pragma strict
import System.IO;
import U3DXT.Core;
import U3DXT.iOS.MediaPlayer;
import U3DXT.iOS.Native.MediaPlayer;
import U3DXT.iOS.Native.Foundation;
import U3DXT.Utils;
import U3DXT.iOS.Native.AVFoundation;
var query : MPMediaQuery;
var mediaItem : MPMediaItem;
var theError : NSError;
var songURL : NSURL;
var theAudioPlayer : AVAudioPlayer;
function Start () {
theError = new NSError();
query = new MPMediaQuery.SongsQuery();
mediaItem = query.items[0] as MPMediaItem;
songURL = new NSURL(mediaItem.PropertyAssetURL);
theAudioPlayer = new AVAudioPlayer(songURL, theError);
theAudioPlayer.Play();
}
//Changing the last two lines to :
theAudioPlayer = new AVAudioPlayer();
Debug.Log("Volume : " + theAudioPlayer.volume);
Results in the following in XCode :
0x17e0e46: vmov d8, r0, r0 <Thread 1: EXC_BAD_ACCESS(code=1, address=0x1c)
in Thread 1 UP_AVAudioPlayer_get_volume
Any help is appreciated,
Thanks!
Brandon
Looking at the Apple docs, it looks like the play function is lower-case, play().
Play() is probably specific for the Audio classes of Unity.
Thanks for the reply. Using lowercase play() results in : ‘play’ is not a member of ‘U3DXT.IOS.Native.AVFoundation.AVAudioPlayer’. Did you mean ‘Play’?
This is because I’m not directly calling apple’s play(), but rather going through the U3DXT wrapper.