All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bugvm.apple.audiotoolbox.AudioServices Maven / Gradle / Ivy

/*
 * Copyright (C) 2013-2015 RoboVM AB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bugvm.apple.audiotoolbox;

/**/
import java.io.*;
import java.nio.*;
import java.util.*;
import com.bugvm.objc.*;
import com.bugvm.objc.annotation.*;
import com.bugvm.objc.block.*;
import com.bugvm.rt.*;
import com.bugvm.rt.annotation.*;
import com.bugvm.rt.bro.*;
import com.bugvm.rt.bro.annotation.*;
import com.bugvm.rt.bro.ptr.*;
import com.bugvm.apple.foundation.*;
import com.bugvm.apple.corefoundation.*;
import com.bugvm.apple.audiounit.*;
import com.bugvm.apple.coreaudio.*;
import com.bugvm.apple.coremidi.*;
/**/

/**/
/**/
/**/@Library("AudioToolbox")/**/
/**/public/**/ class /**/AudioServices/**/ 
    extends /**/CocoaUtility/**/ 
    /**//**/ {

    /**/
    /**/
    
    public interface SystemSoundCompletionListener {
        void onComplete(int systemSoundID);
    }
    
    private static final LongMap completionListeners = new LongMap<>();
    private static final java.lang.reflect.Method cbSystemSoundCompleted;
    
    static {
        try {
            cbSystemSoundCompleted = AudioServices.class.getDeclaredMethod("cbSystemSoundCompleted", Integer.TYPE, Long.TYPE);
        } catch (Throwable e) {
            throw new Error(e);
        }
    }
    
    /**/static { Bro.bind(AudioServices.class); }/**/
    /**/
    public static final int SystemSoundVibrate = 4095;
    /**/
    /**//**/
    /**//**/
    /**//**/
    @Callback
    private static void cbSystemSoundCompleted(int systemSoundID, long clientData) {
        synchronized (completionListeners) {
            completionListeners.get(systemSoundID).onComplete(systemSoundID);
        }
    }
    
    /**
     * @throws OSStatusException 
     * @since Available in iOS 2.0 and later.
     */
    public static int createSystemSoundID(NSURL fileURL) throws OSStatusException {
        IntPtr ptr = new IntPtr();
        OSStatus status = createSystemSoundID0(fileURL, ptr);
        OSStatusException.throwIfNecessary(status);
        return ptr.get();
    }
    /**
     * @throws OSStatusException 
     * @since Available in iOS 2.0 and later.
     */
    public static void disposeSystemSoundID(int systemSoundID) throws OSStatusException {
        OSStatus status = disposeSystemSoundID0(systemSoundID);
        OSStatusException.throwIfNecessary(status);
    }
    /**
     * @throws OSStatusException 
     * @since Available in iOS 2.0 and later.
     */
    public static void addSystemSoundCompletionListener(int systemSoundID, NSRunLoop runLoop, String runLoopMode, SystemSoundCompletionListener listener) throws OSStatusException {
        if (listener == null) {
            throw new NullPointerException("listener");
        }
        OSStatus status = addSystemSoundCompletion0(systemSoundID, runLoop, runLoopMode, new FunctionPtr(cbSystemSoundCompleted), null);
        if (OSStatusException.throwIfNecessary(status)) {
            synchronized (completionListeners) {
                completionListeners.put(systemSoundID, listener);
            }
        }
    }
    /**
     * @since Available in iOS 2.0 and later.
     */
    public static void removeSystemSoundCompletion(int systemSoundID) {
        removeSystemSoundCompletion0(systemSoundID);
        synchronized (completionListeners) {
            completionListeners.remove(systemSoundID);
        }
    }
    /**
     * @throws OSStatusException 
     * @since Available in iOS 2.0 and later.
     */
    public static int getPropertySize(AudioServicesProperty id) throws OSStatusException {
        IntPtr ptr = new IntPtr();
        OSStatus status = getPropertyInfo0(id, 0, null, ptr, null);
        OSStatusException.throwIfNecessary(status);
        return ptr.get();
    }
    /**
     * @throws OSStatusException 
     * @since Available in iOS 2.0 and later.
     */
    public static boolean isPropertyWritable(AudioServicesProperty id) throws OSStatusException {
        BooleanPtr ptr = new BooleanPtr();
        OSStatus status = getPropertyInfo0(id, 0, null, null, ptr);
        OSStatusException.throwIfNecessary(status);
        return ptr.get();
    }
    /**
     * @throws OSStatusException 
     * @since Available in iOS 2.0 and later.
     */
    public static > T getProperty(AudioServicesProperty id, Struct specifier, Class type) throws OSStatusException {
        T data = Struct.allocate(type);
        IntPtr dataSize = new IntPtr(Struct.sizeOf(data));
        OSStatus status = getProperty0(id, specifier == null ? 0 : Struct.sizeOf(specifier), specifier == null ? null : specifier.as(VoidPtr.class), dataSize, data.as(VoidPtr.class));
        OSStatusException.throwIfNecessary(status);
        return data;
    }
    /**
     * @throws OSStatusException 
     * @since Available in iOS 2.0 and later.
     */
    public static > void setProperty(AudioServicesProperty id, Struct specifier, T data) throws OSStatusException {
        OSStatus status = setProperty0(id, specifier == null ? 0 : Struct.sizeOf(specifier), specifier == null ? null : specifier.as(VoidPtr.class), data == null ? 0 : Struct.sizeOf(data), data == null ? null : data.as(VoidPtr.class));
        OSStatusException.throwIfNecessary(status);
    }
    public static boolean isUISound(int systemSoundID) throws OSStatusException {
        IntPtr ptr = new IntPtr(systemSoundID);
        IntPtr result = getProperty(AudioServicesProperty.IsUISound, ptr, IntPtr.class);
        return result.get() == 1;
    }
    public static void setUISound(int systemSoundID, boolean ui) throws OSStatusException {
        IntPtr ptr = new IntPtr(systemSoundID);
        setProperty(AudioServicesProperty.IsUISound, ptr, new IntPtr(ui ? 1 : 0));
    }
    public static boolean completesPlaybackIfAppDies(int systemSoundID) throws OSStatusException {
        IntPtr ptr = new IntPtr(systemSoundID);
        IntPtr result = getProperty(AudioServicesProperty.CompletePlaybackIfAppDies, ptr, IntPtr.class);
        return result.get() == 1;
    }
    public static void setCompletesPlaybackIfAppDies(int systemSoundID, boolean ui) throws OSStatusException {
        IntPtr ptr = new IntPtr(systemSoundID);
        setProperty(AudioServicesProperty.CompletePlaybackIfAppDies, ptr, new IntPtr(ui ? 1 : 0));
    }
    /**/
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="AudioServicesPlayAlertSound", optional=true)
    public static native void playAlertSound(int systemSoundID);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="AudioServicesPlaySystemSound", optional=true)
    public static native void playSystemSound(int systemSoundID);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="AudioServicesCreateSystemSoundID", optional=true)
    protected static native OSStatus createSystemSoundID0(NSURL inFileURL, IntPtr outSystemSoundID);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="AudioServicesDisposeSystemSoundID", optional=true)
    protected static native OSStatus disposeSystemSoundID0(int inSystemSoundID);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="AudioServicesAddSystemSoundCompletion", optional=true)
    protected static native OSStatus addSystemSoundCompletion0(int inSystemSoundID, NSRunLoop inRunLoop, String inRunLoopMode, FunctionPtr inCompletionRoutine, VoidPtr inClientData);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="AudioServicesRemoveSystemSoundCompletion", optional=true)
    protected static native void removeSystemSoundCompletion0(int inSystemSoundID);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="AudioServicesGetPropertyInfo", optional=true)
    protected static native OSStatus getPropertyInfo0(AudioServicesProperty inPropertyID, int inSpecifierSize, VoidPtr inSpecifier, IntPtr outPropertyDataSize, BooleanPtr outWritable);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="AudioServicesGetProperty", optional=true)
    protected static native OSStatus getProperty0(AudioServicesProperty inPropertyID, int inSpecifierSize, VoidPtr inSpecifier, IntPtr ioPropertyDataSize, VoidPtr outPropertyData);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="AudioServicesSetProperty", optional=true)
    protected static native OSStatus setProperty0(AudioServicesProperty inPropertyID, int inSpecifierSize, VoidPtr inSpecifier, int inPropertyDataSize, VoidPtr inPropertyData);
    /**/
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy