mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Add video playback support for Android and iOS. Update VideoComponent API to support building custom UIs.
This commit is contained in:
parent
dc7217fbbb
commit
315326477d
45 changed files with 4293 additions and 308 deletions
146
modules/juce_core/native/java/AndroidVideo.java
Normal file
146
modules/juce_core/native/java/AndroidVideo.java
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
$$VideoApi21
|
||||
//==============================================================================
|
||||
public class MediaControllerCallback extends MediaController.Callback
|
||||
{
|
||||
private native void mediaControllerAudioInfoChanged (long host, MediaController.PlaybackInfo info);
|
||||
private native void mediaControllerMetadataChanged (long host, MediaMetadata metadata);
|
||||
private native void mediaControllerPlaybackStateChanged (long host, PlaybackState state);
|
||||
private native void mediaControllerSessionDestroyed (long host);
|
||||
|
||||
MediaControllerCallback (long hostToUse)
|
||||
{
|
||||
host = hostToUse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAudioInfoChanged (MediaController.PlaybackInfo info)
|
||||
{
|
||||
mediaControllerAudioInfoChanged (host, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMetadataChanged (MediaMetadata metadata)
|
||||
{
|
||||
mediaControllerMetadataChanged (host, metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaybackStateChanged (PlaybackState state)
|
||||
{
|
||||
mediaControllerPlaybackStateChanged (host, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQueueChanged (List<MediaSession.QueueItem> queue) {}
|
||||
|
||||
@Override
|
||||
public void onSessionDestroyed()
|
||||
{
|
||||
mediaControllerSessionDestroyed (host);
|
||||
}
|
||||
|
||||
private long host;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
public class MediaSessionCallback extends MediaSession.Callback
|
||||
{
|
||||
private native void mediaSessionPause (long host);
|
||||
private native void mediaSessionPlay (long host);
|
||||
private native void mediaSessionPlayFromMediaId (long host, String mediaId, Bundle extras);
|
||||
private native void mediaSessionSeekTo (long host, long pos);
|
||||
private native void mediaSessionStop (long host);
|
||||
|
||||
|
||||
MediaSessionCallback (long hostToUse)
|
||||
{
|
||||
host = hostToUse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
mediaSessionPause (host);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlay()
|
||||
{
|
||||
mediaSessionPlay (host);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayFromMediaId (String mediaId, Bundle extras)
|
||||
{
|
||||
mediaSessionPlayFromMediaId (host, mediaId, extras);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSeekTo (long pos)
|
||||
{
|
||||
mediaSessionSeekTo (host, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
mediaSessionStop (host);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFastForward() {}
|
||||
|
||||
@Override
|
||||
public boolean onMediaButtonEvent (Intent mediaButtonIntent)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRewind() {}
|
||||
|
||||
@Override
|
||||
public void onSkipToNext() {}
|
||||
|
||||
@Override
|
||||
public void onSkipToPrevious() {}
|
||||
|
||||
@Override
|
||||
public void onSkipToQueueItem (long id) {}
|
||||
|
||||
private long host;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
public class SystemVolumeObserver extends ContentObserver
|
||||
{
|
||||
private native void mediaSessionSystemVolumeChanged (long host);
|
||||
|
||||
SystemVolumeObserver (Activity activityToUse, long hostToUse)
|
||||
{
|
||||
super (null);
|
||||
|
||||
activity = activityToUse;
|
||||
host = hostToUse;
|
||||
}
|
||||
|
||||
void setEnabled (boolean shouldBeEnabled)
|
||||
{
|
||||
if (shouldBeEnabled)
|
||||
activity.getApplicationContext().getContentResolver().registerContentObserver (android.provider.Settings.System.CONTENT_URI, true, this);
|
||||
else
|
||||
activity.getApplicationContext().getContentResolver().unregisterContentObserver (this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange (boolean selfChange, Uri uri)
|
||||
{
|
||||
if (uri.toString().startsWith ("content://settings/system/volume_music"))
|
||||
mediaSessionSystemVolumeChanged (host);
|
||||
}
|
||||
|
||||
private Activity activity;
|
||||
private long host;
|
||||
}
|
||||
|
||||
VideoApi21$$
|
||||
|
|
@ -30,7 +30,8 @@ import android.content.Intent;
|
|||
import android.content.res.Configuration;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
$$JuceAndroidCameraImports$$ // If you get an error here, you need to re-save your project with the Projucer!
|
||||
$$JuceAndroidCameraImports$$ // If you get an error here, you need to re-save your project with the Projucer!
|
||||
$$JuceAndroidVideoImports$$ // If you get an error here, you need to re-save your project with the Projucer!
|
||||
import android.net.http.SslError;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -87,10 +88,13 @@ public class JuceAppActivity extends $$JuceAppActivityBaseClass$$
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
public boolean isPermissionDeclaredInManifest (int permissionID)
|
||||
public boolean isPermissionDeclaredInManifest (int permissionID)
|
||||
{
|
||||
return isPermissionDeclaredInManifest (getAndroidPermissionName (permissionID));
|
||||
}
|
||||
|
||||
public boolean isPermissionDeclaredInManifest (String permissionToCheck)
|
||||
{
|
||||
String permissionToCheck = getAndroidPermissionName(permissionID);
|
||||
|
||||
try
|
||||
{
|
||||
PackageInfo info = getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), PackageManager.GET_PERMISSIONS);
|
||||
|
|
@ -982,12 +986,14 @@ public class JuceAppActivity extends $$JuceAppActivityBaseClass$$
|
|||
public static class NativeSurfaceView extends SurfaceView
|
||||
implements SurfaceHolder.Callback
|
||||
{
|
||||
private long nativeContext = 0;
|
||||
private long nativeContext = 0;
|
||||
private boolean forVideo;
|
||||
|
||||
NativeSurfaceView (Context context, long nativeContextPtr)
|
||||
NativeSurfaceView (Context context, long nativeContextPtr, boolean createdForVideo)
|
||||
{
|
||||
super (context);
|
||||
nativeContext = nativeContextPtr;
|
||||
nativeContext = nativeContextPtr;
|
||||
forVideo = createdForVideo;
|
||||
}
|
||||
|
||||
public Surface getNativeSurface()
|
||||
|
|
@ -1004,39 +1010,52 @@ public class JuceAppActivity extends $$JuceAppActivityBaseClass$$
|
|||
//==============================================================================
|
||||
@Override
|
||||
public void surfaceChanged (SurfaceHolder holder, int format, int width, int height)
|
||||
{
|
||||
surfaceChangedNative (nativeContext, holder, format, width, height);
|
||||
{
|
||||
if (forVideo)
|
||||
surfaceChangedNativeVideo (nativeContext, holder, format, width, height);
|
||||
else
|
||||
surfaceChangedNative (nativeContext, holder, format, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceCreated (SurfaceHolder holder)
|
||||
{
|
||||
surfaceCreatedNative (nativeContext, holder);
|
||||
{
|
||||
if (forVideo)
|
||||
surfaceCreatedNativeVideo (nativeContext, holder);
|
||||
else
|
||||
surfaceCreatedNative (nativeContext, holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed (SurfaceHolder holder)
|
||||
{
|
||||
surfaceDestroyedNative (nativeContext, holder);
|
||||
{
|
||||
if (forVideo)
|
||||
surfaceDestroyedNativeVideo (nativeContext, holder);
|
||||
else
|
||||
surfaceDestroyedNative (nativeContext, holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw (Canvas canvas)
|
||||
{
|
||||
super.dispatchDraw (canvas);
|
||||
dispatchDrawNative (nativeContext, canvas);
|
||||
super.dispatchDraw (canvas);
|
||||
|
||||
if (forVideo)
|
||||
dispatchDrawNativeVideo (nativeContext, canvas);
|
||||
else
|
||||
dispatchDrawNative (nativeContext, canvas);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
@Override
|
||||
protected void onAttachedToWindow ()
|
||||
protected void onAttachedToWindow()
|
||||
{
|
||||
super.onAttachedToWindow();
|
||||
getHolder().addCallback (this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow ()
|
||||
protected void onDetachedFromWindow()
|
||||
{
|
||||
super.onDetachedFromWindow();
|
||||
getHolder().removeCallback (this);
|
||||
|
|
@ -1047,12 +1066,18 @@ public class JuceAppActivity extends $$JuceAppActivityBaseClass$$
|
|||
private native void surfaceCreatedNative (long nativeContextptr, SurfaceHolder holder);
|
||||
private native void surfaceDestroyedNative (long nativeContextptr, SurfaceHolder holder);
|
||||
private native void surfaceChangedNative (long nativeContextptr, SurfaceHolder holder,
|
||||
int format, int width, int height);
|
||||
int format, int width, int height);
|
||||
|
||||
private native void dispatchDrawNativeVideo (long nativeContextPtr, Canvas canvas);
|
||||
private native void surfaceCreatedNativeVideo (long nativeContextptr, SurfaceHolder holder);
|
||||
private native void surfaceDestroyedNativeVideo (long nativeContextptr, SurfaceHolder holder);
|
||||
private native void surfaceChangedNativeVideo (long nativeContextptr, SurfaceHolder holder,
|
||||
int format, int width, int height);
|
||||
}
|
||||
|
||||
public NativeSurfaceView createNativeSurfaceView (long nativeSurfacePtr)
|
||||
public NativeSurfaceView createNativeSurfaceView (long nativeSurfacePtr, boolean forVideo)
|
||||
{
|
||||
return new NativeSurfaceView (this, nativeSurfacePtr);
|
||||
return new NativeSurfaceView (this, nativeSurfacePtr, forVideo);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -1610,7 +1635,8 @@ $$JuceAndroidWebViewNativeCode$$ // If you get an error here, you need to re-sav
|
|||
private final Object hostLock = new Object();
|
||||
}
|
||||
|
||||
$$JuceAndroidCameraCode$$ // If you get an error here, you need to re-save your project with the Projucer!
|
||||
$$JuceAndroidCameraCode$$ // If you get an error here, you need to re-save your project with the Projucer!
|
||||
$$JuceAndroidVideoCode$$ // If you get an error here, you need to re-save your project with the Projucer!
|
||||
|
||||
//==============================================================================
|
||||
public static final String getLocaleValue (boolean isRegion)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue