Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: phoboslab/Ejecta
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: TrompoGames/Ejecta
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 8 commits
  • 2 files changed
  • 3 contributors

Commits on Oct 17, 2014

  1. -[AUDIO] Implemented appendChild, insertBefore and removeChild functi…

    …ons to be able to use "source" type elements to provide a list of source files.
    Dario Segura committed Oct 17, 2014
    Copy the full SHA
    f290e24 View commit details

Commits on Nov 3, 2014

  1. Merge branch 'master' of github.com:TrompoGames/Ejecta

    Dario Segura committed Nov 3, 2014
    Copy the full SHA
    7bff744 View commit details

Commits on Dec 9, 2014

  1. Merge branch 'master' of github.com:phoboslab/Ejecta

    Dario Segura committed Dec 9, 2014
    Copy the full SHA
    f8f9775 View commit details
  2. -[ORIENTATION] Solves crash caused by Info.plist file using the "UISu…

    …pportedInterfaceOrientations" instead of "UIInterfaceOrientation"
    Dario Segura committed Dec 9, 2014
    Copy the full SHA
    c398688 View commit details

Commits on Jan 21, 2015

  1. Merge branch 'master' of github.com:phoboslab/Ejecta

    # By Dominic Szablewski (19) and Dario Segura (2)
    # Via Dominic Szablewski
    * 'master' of github.com:phoboslab/Ejecta: (21 commits)
      Embed GL shaders in source; close #444
      Cosmetics: clean up Canvas Context creation
      Removed contentScale warning; see #441
      Removed obsolete section about architectures in README
      Compile for arm64 as well by default; new fat JSC lib
      Use NSData's base64 encoder for DataURIs
      Added support for gradient & pattern strokes; close #455
      Cosmetics
      -[ORIENTATION] Solves crash caused by Info.plist file using the "UISupportedInterfaceOrientations" key instead of "UIInterfaceOrientation"
      Fixed deprecations for GameCenter
      Fixed various deprecated stuff
      Removed deprecated volume property for Videos
      Update SocketRocket lib
      Added .playbackRate property for Audio; close #388
      Update Deployment Target to iOS 8 to silence launch screen warning
      Allow 3x retina scaling for iPhone6; fix #453
      Use XIB for launch screen; close #420
      Make xhr response and responseText enumerable; see #448
      Cosmetics
      Properly release WebGL extensions. See #442
      ...
    Dario Segura committed Jan 21, 2015
    Copy the full SHA
    f16093d View commit details
  2. Merge branch 'master' of github.com:TrompoGames/Ejecta

    * 'master' of github.com:TrompoGames/Ejecta:
      -[ORIENTATION] Solves crash caused by Info.plist file using the "UISupportedInterfaceOrientations" instead of "UIInterfaceOrientation"
    Dario Segura committed Jan 21, 2015
    Copy the full SHA
    759e000 View commit details

Commits on Oct 20, 2015

  1. Merge branch 'master' of github.com:phoboslab/Ejecta

    Dario Segura committed Oct 20, 2015
    Copy the full SHA
    e4bfa73 View commit details

Commits on May 17, 2023

  1. Merge pull request #2 from phoboslab/master

    [UPDATE] Merge latest version of ejecta
    darionco authored May 17, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e95f1ef View commit details
Showing with 123 additions and 8 deletions.
  1. +5 −0 Source/Ejecta/EJAudio/EJBindingAudio.h
  2. +118 −8 Source/Ejecta/EJAudio/EJBindingAudio.m
5 changes: 5 additions & 0 deletions Source/Ejecta/EJAudio/EJBindingAudio.h
Original file line number Diff line number Diff line change
@@ -34,9 +34,14 @@ typedef enum {
BOOL loading, playAfterLoad;
float volume, playbackRate;
NSOperation *loadCallback;
NSMutableArray *children;
}

- (void)load;
- (void)appendChild:(NSDictionary*)element;
- (void)insertBefore:(NSDictionary*)newElement oldElement:(JSObjectRef)oldElement;
- (void)removeChild:(JSObjectRef)element;
- (BOOL)canPlayType:(NSString*)mimeType;
- (void)setSourcePath:(NSString *)pathp;

@property (nonatomic) BOOL loop;
126 changes: 118 additions & 8 deletions Source/Ejecta/EJAudio/EJBindingAudio.m
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@
#import "EJJavaScriptView.h"
#import "EJNonRetainingProxy.h"

NSString * const kEJBindingAudio_elementContext = @"context";
NSString * const kEJBindingAudio_elementObject = @"object";

@implementation EJBindingAudio

@synthesize loop, ended, volume;
@@ -13,6 +16,7 @@ - (id)initWithContext:(JSContextRef)ctx argc:(size_t)argc argv:(const JSValueRef
volume = 1;
paused = true;
preload = kEJAudioPreloadNone;
children = [[NSMutableArray alloc] init];

if( argc > 0 ) {
[self setSourcePath:JSValueToNSString(ctx, argv[0])];
@@ -28,6 +32,13 @@ - (void)dealloc {
source.delegate = nil;
[source release];
[path release];

for (NSDictionary *element in children)
{
JSValueUnprotectSafe([[element objectForKey:kEJBindingAudio_elementContext] pointerValue], [[element objectForKey:kEJBindingAudio_elementObject] pointerValue]);
}
[children release];

[super dealloc];
}

@@ -45,10 +56,34 @@ - (void)setSourcePath:(NSString *)pathp {
}

- (void)load {
if( source || !path || loading ) { return; }
if( source || (!path && !children.count) || loading ) { return; }

// This will begin loading the sound in a background thread
loading = YES;

if (!path)
{
/* find the first appropriate file to load based on the supported types */
JSStringRef type = JSStringCreateWithCFString((CFStringRef)@"type");
for (NSDictionary *element in children)
{
JSObjectRef child = [[element objectForKey:kEJBindingAudio_elementObject] pointerValue];
JSContextRef context = [[element objectForKey:kEJBindingAudio_elementContext] pointerValue];
JSValueRef mimeType = JSObjectGetProperty(context, child, type, NULL);
if ([self canPlayType:JSValueToNSString(context, mimeType)])
{
JSStringRef src = JSStringCreateWithCFString((CFStringRef)@"src");
JSValueRef srcValue = JSObjectGetProperty(context, child, src, NULL);
path = JSValueToNSString(context, srcValue);
[path retain];
JSStringRelease(src);
break;
}
}
JSStringRelease(type);
}

if (!path) { return; }

// Protect this Audio object from garbage collection, as its callback function
// may be the only thing holding on to it
@@ -67,6 +102,61 @@ - (void)load {
[loadOp release];
}

- (void)appendChild:(NSDictionary*)element
{
JSValueProtect([[element objectForKey:kEJBindingAudio_elementContext] pointerValue], [[element objectForKey:kEJBindingAudio_elementObject] pointerValue]);
[children addObject:element];
}

- (void)insertBefore:(NSDictionary*)newElement oldElement:(JSObjectRef)oldElement
{
int i;
for (i = 0; i < children.count; ++i)
{
JSObjectRef element = [[children[i] objectForKey:kEJBindingAudio_elementObject] pointerValue];
JSContextRef context = [[children[i] objectForKey:kEJBindingAudio_elementContext] pointerValue];
if (JSValueIsEqual(context, element, oldElement, NULL))
{
break;
}
}

JSValueProtect([[newElement objectForKey:kEJBindingAudio_elementContext] pointerValue], [[newElement objectForKey:kEJBindingAudio_elementObject] pointerValue]);
if (i < children.count)
{
[children insertObject:newElement atIndex:i];
}
else
{
[children addObject:newElement];
}
}

- (void)removeChild:(JSObjectRef)element
{
for (int i = 0; i < children.count; ++i)
{
JSObjectRef tester = [[children[i] objectForKey:kEJBindingAudio_elementObject] pointerValue];
JSContextRef context = [[children[i] objectForKey:kEJBindingAudio_elementContext] pointerValue];
if (JSValueIsEqual(context, element, tester, NULL))
{
JSValueUnprotectSafe(context, element);
[children removeObjectAtIndex:i];
break;
}
}
}

- (BOOL)canPlayType:(NSString*)mimeType
{
return (
[mimeType hasPrefix:@"audio/x-caf"] ||
[mimeType hasPrefix:@"audio/mpeg"] ||
[mimeType hasPrefix:@"audio/mp4"] ||
[mimeType hasPrefix:@"audio/wav"]
);
}

- (void)prepareGarbageCollection {
[loadCallback cancel];
}
@@ -153,15 +243,11 @@ - (void)setPreload:(EJAudioPreload)preloadp {
EJ_BIND_FUNCTION(canPlayType, ctx, argc, argv) {
if( argc != 1 ) return NSStringToJSValue(ctx, @"");

NSString *mime = JSValueToNSString(ctx, argv[0]);
if(
[mime hasPrefix:@"audio/x-caf"] ||
[mime hasPrefix:@"audio/mpeg"] ||
[mime hasPrefix:@"audio/mp4"]
) {
if([self canPlayType:JSValueToNSString(ctx, argv[0])])
{
return NSStringToJSValue(ctx, @"probably");
}
return NSStringToJSValue(ctx, @"");
return NSStringToJSValue(ctx, @"maybe");
}

EJ_BIND_FUNCTION(cloneNode, ctx, argc, argv) {
@@ -183,6 +269,30 @@ - (void)setPreload:(EJAudioPreload)preloadp {
return clone;
}

EJ_BIND_FUNCTION(appendChild, ctx, argc, argv)
{
if( argc != 1 ) return NULL;
[self appendChild:@{kEJBindingAudio_elementContext : [NSValue valueWithPointer:ctx],
kEJBindingAudio_elementObject : [NSValue valueWithPointer:argv[0]] }];
return NULL;
}

EJ_BIND_FUNCTION(insertBefore, ctx, argc, argv)
{
if( argc != 2 ) return NULL;
[self insertBefore:@{ kEJBindingAudio_elementContext : [NSValue valueWithPointer:ctx],
kEJBindingAudio_elementObject : [NSValue valueWithPointer:argv[0]] }
oldElement:JSValueToObject(ctx, argv[1], NULL)];
return NULL;
}

EJ_BIND_FUNCTION(removeChild, ctx, argc, argv)
{
if( argc != 1 ) return NULL;
[self removeChild:JSValueToObject(ctx, argv[0], NULL)];
return NULL;
}

EJ_BIND_GET(duration, ctx) {
return JSValueMakeNumber(ctx, source.duration);
}