|
312
|
|
* Note that the cross domain redirection is allowed by default, but that can be
|
|
313
|
|
* changed with key/value pairs through the headers parameter with
|
|
314
|
|
* "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value
|
|
315
|
|
* to disallow or allow cross domain redirection.
|
|
316
|
|
* @throws IllegalStateException if it is called in an invalid state
|
|
317
|
|
*/
|
|
318
|
|
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
|
319
|
|
@Override
|
|
320
|
|
public void setDataSource(Context context, Uri uri, Map<String, String> headers)
|
|
321
|
|
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
|
|
322
|
|
final String scheme = uri.getScheme();
|
|
323
|
|
if (ContentResolver.SCHEME_FILE.equals(scheme)) {
|
|
324
|
|
setDataSource(uri.getPath());
|
|
325
|
|
return;
|
|
326
|
|
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)
|
|
327
|
|
&& Settings.AUTHORITY.equals(uri.getAuthority())) {
|
|
328
|
|
// Redirect ringtones to go directly to underlying provider
|
|
329
|
|
uri = RingtoneManager.getActualDefaultRingtoneUri(context,
|
|
330
|
|
RingtoneManager.getDefaultType(uri));
|
|
331
|
|
if (uri == null) {
|
|
332
|
|
throw new FileNotFoundException("Failed to resolve default ringtone");
|
|
333
|
|
}
|
|
334
|
|
}
|
|
335
|
|
|
|
336
|
|
AssetFileDescriptor fd = null;
|
|
337
|
|
try {
|
|
338
|
|
ContentResolver resolver = context.getContentResolver();
|
|
339
|
|
fd = resolver.openAssetFileDescriptor(uri, "r");
|
|
340
|
|
if (fd == null) {
|
|
341
|
|
return;
|
|
342
|
|
}
|
|
343
|
|
// Note: using getDeclaredLength so that our behavior is the same
|
|
344
|
|
// as previous versions when the content provider is returning
|
|
345
|
|
// a full file.
|
|
346
|
|
if (fd.getDeclaredLength() < 0) {
|
|
347
|
|
setDataSource(fd.getFileDescriptor());
|
|
348
|
|
} else {
|
|
349
|
|
setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getDeclaredLength());
|
|
350
|
|
}
|
|
351
|
|
return;
|
|
352
|
|
} catch (SecurityException ignored) {
|
|
353
|
|
} catch (IOException ignored) {
|
|
354
|
|
} finally {
|
|
355
|
|
if (fd != null) {
|
|
356
|
|
fd.close();
|
|
357
|
|
}
|
|
358
|
|
}
|
|
359
|
|
|
|
360
|
|
Log.d(TAG, "Couldn't open file on client side, trying server side");
|
|
361
|
|
|
|
362
|
|
setDataSource(uri.toString(), headers);
|
|
363
|
|
}
|
|
364
|
|
|
|
365
|
|
/**
|
|
366
|
|
* Sets the data source (file-path or http/rtsp URL) to use.
|
|
367
|
|
*
|
|
368
|
|
* @param path
|
|
369
|
|
* the path of the file, or the http/rtsp URL of the stream you
|
|
370
|
|
* want to play
|
|
371
|
|
* @throws IllegalStateException
|
|
372
|
|
* if it is called in an invalid state
|
|
373
|
|
*
|
|
374
|
|
* <p>
|
|
375
|
|
* When <code>path</code> refers to a local file, the file may
|
|
376
|
|
* actually be opened by a process other than the calling
|
|
377
|
|
* application. This implies that the pathname should be an
|
|
378
|
|
* absolute path (as any other process runs with unspecified
|
|
379
|
|
* current working directory), and that the pathname should
|
|
380
|
|
* reference a world-readable file.
|
|
381
|
|
*/
|
|
382
|
|
@Override
|
|
383
|
|
public void setDataSource(String path)
|
|
384
|
|
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
|
|
385
|
|
mDataSource = path;
|
|
386
|
|
_setDataSource(path, null, null);
|
|
387
|
|
}
|
|
388
|
|
|
|
389
|
|
/**
|
|
390
|
|
* Sets the data source (file-path or http/rtsp URL) to use.
|
|
391
|
|
*
|
|
392
|
|
* @param path the path of the file, or the http/rtsp URL of the stream you want to play
|
|
393
|
|
* @param headers the headers associated with the http request for the stream you want to play
|
|
394
|
|
* @throws IllegalStateException if it is called in an invalid state
|
|
395
|
|
*/
|
|
396
|
|
public void setDataSource(String path, Map<String, String> headers)
|
|
397
|
|
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException
|
|
398
|
|
{
|
|
399
|
|
if (headers != null && !headers.isEmpty()) {
|
|
400
|
|
StringBuilder sb = new StringBuilder();
|
|
401
|
|
for(Map.Entry<String, String> entry: headers.entrySet()) {
|
|
402
|
|
sb.append(entry.getKey());
|
|
403
|
|
sb.append(":");
|
|
404
|
|
String value = entry.getValue();
|
|
405
|
|
if (!TextUtils.isEmpty(value))
|
|
406
|
|
sb.append(entry.getValue());
|
|
407
|
|
sb.append("\r\n");
|
|
408
|
|
setOption(OPT_CATEGORY_FORMAT, "headers", sb.toString());
|
|
409
|
|
}
|
|
410
|
|
}
|
|
411
|
|
setDataSource(path);
|
|
412
|
|
}
|
|
413
|
|
|
|
414
|
|
/**
|
|
415
|
|
* Sets the data source (FileDescriptor) to use. It is the caller's responsibility
|
|
416
|
|
* to close the file descriptor. It is safe to do so as soon as this call returns.
|
|
417
|
|
*
|
|
418
|
|
* @param fd the FileDescriptor for the file you want to play
|
|
419
|
|
* @throws IllegalStateException if it is called in an invalid state
|
|
420
|
|
*/
|
|
421
|
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
|
|
422
|
|
@Override
|
|
423
|
|
public void setDataSource(FileDescriptor fd)
|
|
424
|
|
throws IOException, IllegalArgumentException, IllegalStateException {
|
|
425
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
|
|
426
|
|
int native_fd = -1;
|
|
427
|
|
try {
|
|
428
|
|
Field f = fd.getClass().getDeclaredField("descriptor"); //NoSuchFieldException
|
|
429
|
|
f.setAccessible(true);
|
|
430
|
|
native_fd = f.getInt(fd); //IllegalAccessException
|
|
431
|
|
} catch (NoSuchFieldException e) {
|
|
432
|
|
throw new RuntimeException(e);
|
|
433
|
|
} catch (IllegalAccessException e) {
|
|
434
|
|
throw new RuntimeException(e);
|
|
435
|
|
}
|
|
436
|
|
_setDataSourceFd(native_fd);
|
|
437
|
|
} else {
|
|
438
|
|
ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(fd);
|
|
439
|
|
try {
|
|
440
|
|
_setDataSourceFd(pfd.getFd());
|
|
441
|
|
} finally {
|
|
442
|
|
pfd.close();
|
|
443
|
|
}
|
|
444
|
|
}
|
|
445
|
|
}
|
|
446
|
|
|
|
447
|
|
/**
|
|
448
|
|
* Sets the data source (FileDescriptor) to use. The FileDescriptor must be
|
|
449
|
|
* seekable (N.B. a LocalSocket is not seekable). It is the caller's responsibility
|
|
450
|
|
* to close the file descriptor. It is safe to do so as soon as this call returns.
|
|
451
|
|
*
|
|
452
|
|
* @param fd the FileDescriptor for the file you want to play
|
|
453
|
|
* @param offset the offset into the file where the data to be played starts, in bytes
|
|
454
|
|
* @param length the length in bytes of the data to be played
|
|
455
|
|
* @throws IllegalStateException if it is called in an invalid state
|
|
456
|
|
*/
|
|
457
|
|
private void setDataSource(FileDescriptor fd, long offset, long length)
|
|
458
|
|
throws IOException, IllegalArgumentException, IllegalStateException {
|
|
459
|
|
// FIXME: handle offset, length
|
|
460
|
|
setDataSource(fd);
|
|
461
|
|
}
|
|
462
|
|
|
|
463
|
|
public void setDataSource(IMediaDataSource mediaDataSource)
|
|
464
|
|
throws IllegalArgumentException, SecurityException, IllegalStateException {
|
|
465
|
|
_setDataSource(mediaDataSource);
|
|
466
|
|
}
|
|
467
|
|
|
|
468
|
|
private native void _setDataSource(String path, String[] keys, String[] values)
|
|
469
|
|
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
|
|
470
|
|
|
|
471
|
|
private native void _setDataSourceFd(int fd)
|
|
472
|
|
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
|
|
473
|
|
|
|
474
|
|
private native void _setDataSource(IMediaDataSource mediaDataSource)
|
|
475
|
|
throws IllegalArgumentException, SecurityException, IllegalStateException;
|
|
476
|
|
|
|
477
|
|
@Override
|
|
478
|
|
public String getDataSource() {
|
|
479
|
|
return mDataSource;
|
|
480
|
|
}
|
|
481
|
|
|
|
482
|
|
@Override
|
|
483
|
|
public void prepareAsync() throws IllegalStateException {
|
|
484
|
|
_prepareAsync();
|
|
485
|
|
}
|
|
486
|
|
|
|
487
|
|
public native void _prepareAsync() throws IllegalStateException;
|
|
488
|
|
|
|
489
|
|
@Override
|
|
490
|
|
public void start() throws IllegalStateException {
|
|
491
|
|
stayAwake(true);
|
|
492
|
|
_start();
|
|
493
|
|
}
|
|
494
|
|
|
|
495
|
|
private native void _start() throws IllegalStateException;
|
|
496
|
|
|
|
497
|
|
@Override
|
|
498
|
|
public void stop() throws IllegalStateException {
|
|
499
|
|
stayAwake(false);
|
|
500
|
|
_stop();
|
|
501
|
|
}
|
|
502
|
|
|
|
503
|
|
private native void _stop() throws IllegalStateException;
|
|
504
|
|
|
|
505
|
|
@Override
|
|
506
|
|
public void pause() throws IllegalStateException {
|
|
507
|
|
stayAwake(false);
|
|
508
|
|
_pause();
|
|
509
|
|
}
|
|
510
|
|
|
|
511
|
|
private native void _pause() throws IllegalStateException;
|
|
512
|
|
|
|
513
|
|
@SuppressLint("Wakelock")
|
|
514
|
|
@Override
|
|
515
|
|
public void setWakeMode(Context context, int mode) {
|
|
516
|
|
boolean washeld = false;
|
|
517
|
|
if (mWakeLock != null) {
|
|
518
|
|
if (mWakeLock.isHeld()) {
|
|
519
|
|
washeld = true;
|
|
520
|
|
mWakeLock.release();
|
|
521
|
|
}
|
|
522
|
|
mWakeLock = null;
|
|
523
|
|
}
|
|
524
|
|
|
|
525
|
|
PowerManager pm = (PowerManager) context
|
|
526
|
|
.getSystemService(Context.POWER_SERVICE);
|
|
527
|
|
mWakeLock = pm.newWakeLock(mode | PowerManager.ON_AFTER_RELEASE,
|
|
528
|
|
IjkMediaPlayer.class.getName());
|
|
529
|
|
mWakeLock.setReferenceCounted(false);
|
|
530
|
|
if (washeld) {
|
|
531
|
|
mWakeLock.acquire();
|
|
532
|
|
}
|
|
533
|
|
}
|
|
534
|
|
|
|
535
|
|
@Override
|
|
536
|
|
public void setScreenOnWhilePlaying(boolean screenOn) {
|
|
537
|
|
if (mScreenOnWhilePlaying != screenOn) {
|
|
538
|
|
if (screenOn && mSurfaceHolder == null) {
|
|
539
|
|
DebugLog.w(TAG,
|
|
540
|
|
"setScreenOnWhilePlaying(true) is ineffective without a SurfaceHolder");
|
|
541
|
|
}
|
|
542
|
|
mScreenOnWhilePlaying = screenOn;
|
|
543
|
|
updateSurfaceScreenOn();
|
|
544
|
|
}
|
|
545
|
|
}
|
|
546
|
|
|
|
547
|
|
@SuppressLint("Wakelock")
|
|
548
|
|
private void stayAwake(boolean awake) {
|
|
549
|
|
if (mWakeLock != null) {
|
|
550
|
|
if (awake && !mWakeLock.isHeld()) {
|
|
551
|
|
mWakeLock.acquire();
|
|
552
|
|
} else if (!awake && mWakeLock.isHeld()) {
|
|
553
|
|
mWakeLock.release();
|
|
554
|
|
}
|
|
555
|
|
}
|
|
556
|
|
mStayAwake = awake;
|
|
557
|
|
updateSurfaceScreenOn();
|
|
558
|
|
}
|
|
559
|
|
|
|
560
|
|
private void updateSurfaceScreenOn() {
|
|
561
|
|
if (mSurfaceHolder != null) {
|
|
562
|
|
mSurfaceHolder.setKeepScreenOn(mScreenOnWhilePlaying && mStayAwake);
|
|
563
|
|
}
|
|
564
|
|
}
|
|
565
|
|
|
|
566
|
|
@Override
|
|
567
|
|
public IjkTrackInfo[] getTrackInfo() {
|
|
568
|
|
Bundle bundle = getMediaMeta();
|
|
569
|
|
if (bundle == null)
|
|
570
|
|
return null;
|
|
571
|
|
|
|
572
|
|
IjkMediaMeta mediaMeta = IjkMediaMeta.parse(bundle);
|
|
573
|
|
if (mediaMeta == null || mediaMeta.mStreams == null)
|
|
574
|
|
return null;
|
|
575
|
|
|
|
576
|
|
ArrayList<IjkTrackInfo> trackInfos = new ArrayList<IjkTrackInfo>();
|
|
577
|
|
for (IjkMediaMeta.IjkStreamMeta streamMeta: mediaMeta.mStreams) {
|
|
578
|
|
IjkTrackInfo trackInfo = new IjkTrackInfo(streamMeta);
|
|
579
|
|
if (streamMeta.mType.equalsIgnoreCase(IjkMediaMeta.IJKM_VAL_TYPE__VIDEO)) {
|
|
580
|
|
trackInfo.setTrackType(ITrackInfo.MEDIA_TRACK_TYPE_VIDEO);
|
|
581
|
|
} else if (streamMeta.mType.equalsIgnoreCase(IjkMediaMeta.IJKM_VAL_TYPE__AUDIO)) {
|
|
582
|
|
trackInfo.setTrackType(ITrackInfo.MEDIA_TRACK_TYPE_AUDIO);
|
|
583
|
|
}
|
|
584
|
|
trackInfos.add(trackInfo);
|
|
585
|
|
}
|
|
586
|
|
|
|
587
|
|
return trackInfos.toArray(new IjkTrackInfo[trackInfos.size()]);
|
|
588
|
|
}
|
|
589
|
|
|
|
590
|
|
// TODO: @Override
|
|
591
|
|
public int getSelectedTrack(int trackType) {
|
|
592
|
|
switch (trackType) {
|
|
593
|
|
case ITrackInfo.MEDIA_TRACK_TYPE_VIDEO:
|
|
594
|
|
return (int)_getPropertyLong(FFP_PROP_INT64_SELECTED_VIDEO_STREAM, -1);
|
|
595
|
|
case ITrackInfo.MEDIA_TRACK_TYPE_AUDIO:
|
|
596
|
|
return (int)_getPropertyLong(FFP_PROP_INT64_SELECTED_AUDIO_STREAM, -1);
|
|
597
|
|
default:
|
|
598
|
|
return -1;
|
|
599
|
|
}
|
|
600
|
|
}
|
|
601
|
|
|
|
602
|
|
// experimental, should set DEFAULT_MIN_FRAMES and MAX_MIN_FRAMES to 25
|
|
603
|
|
// TODO: @Override
|
|
604
|
|
public void selectTrack(int track) {
|
|
605
|
|
_setStreamSelected(track, true);
|
|
606
|
|
}
|
|
607
|
|
|
|
608
|
|
// experimental, should set DEFAULT_MIN_FRAMES and MAX_MIN_FRAMES to 25
|
|
609
|
|
// TODO: @Override
|
|
610
|
|
public void deselectTrack(int track) {
|
|
611
|
|
_setStreamSelected(track, false);
|
|
612
|
|
}
|
|
613
|
|
|
|
614
|
|
private native void _setStreamSelected(int stream, boolean select);
|
|
615
|
|
|
|
616
|
|
@Override
|
|
617
|
|
public int getVideoWidth() {
|
|
618
|
|
return mVideoWidth;
|
|
619
|
|
}
|
|
620
|
|
|
|
621
|
|
@Override
|
|
622
|
|
public int getVideoHeight() {
|
|
623
|
|
return mVideoHeight;
|
|
624
|
|
}
|
|
625
|
|
|
|
626
|
|
@Override
|
|
627
|
|
public int getVideoSarNum() {
|
|
628
|
|
return mVideoSarNum;
|
|
629
|
|
}
|
|
630
|
|
|
|
631
|
|
@Override
|
|
632
|
|
public int getVideoSarDen() {
|
|
633
|
|
return mVideoSarDen;
|
|
634
|
|
}
|
|
635
|
|
|
|
636
|
|
@Override
|
|
637
|
|
public native boolean isPlaying();
|
|
638
|
|
|
|
639
|
|
@Override
|
|
640
|
|
public native void seekTo(long msec) throws IllegalStateException;
|
|
641
|
|
|
|
642
|
|
@Override
|
|
643
|
|
public native long getCurrentPosition();
|
|
644
|
|
|
|
645
|
|
@Override
|
|
646
|
|
public native long getDuration();
|
|
647
|
|
|
|
648
|
|
/**
|
|
649
|
|
* Releases resources associated with this IjkMediaPlayer object. It is
|
|
650
|
|
* considered good practice to call this method when you're done using the
|
|
651
|
|
* IjkMediaPlayer. In particular, whenever an Activity of an application is
|
|
652
|
|
* paused (its onPause() method is called), or stopped (its onStop() method
|
|
653
|
|
* is called), this method should be invoked to release the IjkMediaPlayer
|
|
654
|
|
* object, unless the application has a special need to keep the object
|
|
655
|
|
* around. In addition to unnecessary resources (such as memory and
|
|
656
|
|
* instances of codecs) being held, failure to call this method immediately
|
|
657
|
|
* if a IjkMediaPlayer object is no longer needed may also lead to
|
|
658
|
|
* continuous battery consumption for mobile devices, and playback failure
|
|
659
|
|
* for other applications if no multiple instances of the same codec are
|
|
660
|
|
* supported on a device. Even if multiple instances of the same codec are
|
|
661
|
|
* supported, some performance degradation may be expected when unnecessary
|
|
662
|
|
* multiple instances are used at the same time.
|
|
663
|
|
*/
|
|
664
|
|
@Override
|
|
665
|
|
public void release() {
|
|
666
|
|
stayAwake(false);
|
|
667
|
|
updateSurfaceScreenOn();
|
|
668
|
|
resetListeners();
|
|
669
|
|
_release();
|
|
670
|
|
}
|
|
671
|
|
|
|
672
|
|
private native void _release();
|
|
673
|
|
|
|
674
|
|
@Override
|
|
675
|
|
public void reset() {
|
|
676
|
|
stayAwake(false);
|
|
677
|
|
_reset();
|
|
678
|
|
// make sure none of the listeners get called anymore
|
|
679
|
|
mEventHandler.removeCallbacksAndMessages(null);
|
|
680
|
|
|
|
681
|
|
mVideoWidth = 0;
|
|
682
|
|
mVideoHeight = 0;
|
|
683
|
|
}
|
|
684
|
|
|
|
685
|
|
private native void _reset();
|
|
686
|
|
|
|
687
|
|
/**
|
|
688
|
|
* Sets the player to be looping or non-looping.
|
|
689
|
|
*
|
|
690
|
|
* @param looping whether to loop or not
|
|
691
|
|
*/
|
|
692
|
|
@Override
|
|
693
|
|
public void setLooping(boolean looping) {
|
|
694
|
|
int loopCount = looping ? 0 : 1;
|
|
695
|
|
setOption(OPT_CATEGORY_PLAYER, "loop", loopCount);
|
|
696
|
|
_setLoopCount(loopCount);
|
|
697
|
|
}
|
|
698
|
|
|
|
699
|
|
private native void _setLoopCount(int loopCount);
|
|
700
|
|
|
|
701
|
|
/**
|
|
702
|
|
* Checks whether the MediaPlayer is looping or non-looping.
|
|
703
|
|
*
|
|
704
|
|
* @return true if the MediaPlayer is currently looping, false otherwise
|
|
705
|
|
*/
|
|
706
|
|
@Override
|
|
707
|
|
public boolean isLooping() {
|
|
708
|
|
int loopCount = _getLoopCount();
|
|
709
|
|
return loopCount != 1;
|
|
710
|
|
}
|
|
711
|
|
|
|
712
|
|
private native int _getLoopCount();
|
|
713
|
|
|
|
714
|
|
@TargetApi(Build.VERSION_CODES.M)
|
|
715
|
|
public void setSpeed(float speed) {
|
|
716
|
|
_setPropertyFloat(FFP_PROP_FLOAT_PLAYBACK_RATE, speed);
|
|
717
|
|
}
|
|
718
|
|
|
|
719
|
|
@TargetApi(Build.VERSION_CODES.M)
|
|
720
|
|
public float getSpeed(float speed) {
|
|
721
|
|
return _getPropertyFloat(FFP_PROP_FLOAT_PLAYBACK_RATE, .0f);
|
|
722
|
|
}
|
|
723
|
|
|
|
724
|
|
public int getVideoDecoder() {
|
|
725
|
|
return (int)_getPropertyLong(FFP_PROP_INT64_VIDEO_DECODER, FFP_PROPV_DECODER_UNKNOWN);
|
|
726
|
|
}
|
|
727
|
|
|
|
728
|
|
public float getVideoOutputFramesPerSecond() {
|
|
729
|
|
return _getPropertyFloat(PROP_FLOAT_VIDEO_OUTPUT_FRAMES_PER_SECOND, 0.0f);
|
|
730
|
|
}
|
|
731
|
|
|
|
732
|
|
public float getVideoDecodeFramesPerSecond() {
|
|
733
|
|
return _getPropertyFloat(PROP_FLOAT_VIDEO_DECODE_FRAMES_PER_SECOND, 0.0f);
|
|
734
|
|
}
|
|
735
|
|
|
|
736
|
|
public long getVideoCachedDuration() {
|
|
737
|
|
return _getPropertyLong(FFP_PROP_INT64_VIDEO_CACHED_DURATION, 0);
|
|
738
|
|
}
|
|
739
|
|
|
|
740
|
|
public long getAudioCachedDuration() {
|
|
741
|
|
return _getPropertyLong(FFP_PROP_INT64_AUDIO_CACHED_DURATION, 0);
|
|
742
|
|
}
|
|
743
|
|
|
|
744
|
|
public long getVideoCachedBytes() {
|
|
745
|
|
return _getPropertyLong(FFP_PROP_INT64_VIDEO_CACHED_BYTES, 0);
|
|
746
|
|
}
|
|
747
|
|
|
|
748
|
|
public long getAudioCachedBytes() {
|
|
749
|
|
return _getPropertyLong(FFP_PROP_INT64_AUDIO_CACHED_BYTES, 0);
|
|
750
|
|
}
|
|
751
|
|
|
|
752
|
|
public long getVideoCachedPackets() {
|
|
753
|
|
return _getPropertyLong(FFP_PROP_INT64_VIDEO_CACHED_PACKETS, 0);
|
|
754
|
|
}
|
|
755
|
|
|
|
756
|
|
public long getAudioCachedPackets() {
|
|
757
|
|
return _getPropertyLong(FFP_PROP_INT64_AUDIO_CACHED_PACKETS, 0);
|
|
758
|
|
}
|
|
759
|
|
|
|
760
|
|
public long getBitrate() {
|
|
761
|
|
return _getPropertyLong(FFP_PROP_INT64_BIT_RATE, 0);
|
|
762
|
|
}
|
|
763
|
|
|
|
764
|
|
public long getTcpSpeed() {
|
|
765
|
|
return _getPropertyLong(FFP_PROP_INT64_TCP_SPEED, 0);
|
|
766
|
|
}
|
|
767
|
|
|
|
768
|
|
public long getSeekLoadDuration() {
|
|
769
|
|
return _getPropertyLong(FFP_PROP_INT64_LATEST_SEEK_LOAD_DURATION, 0);
|
|
770
|
|
}
|
|
771
|
|
|
|
772
|
|
private native float _getPropertyFloat(int property, float defaultValue);
|
|
773
|
|
private native void _setPropertyFloat(int property, float value);
|
|
774
|
|
private native long _getPropertyLong(int property, long defaultValue);
|
|
775
|
|
private native void _setPropertyLong(int property, long value);
|
|
776
|
|
|
|
777
|
|
@Override
|
|
778
|
|
public native void setVolume(float leftVolume, float rightVolume);
|
|
779
|
|
|
|
780
|
|
@Override
|
|
781
|
|
public native int getAudioSessionId();
|
|
782
|
|
|
|
783
|
|
@Override
|
|
784
|
|
public MediaInfo getMediaInfo() {
|
|
785
|
|
MediaInfo mediaInfo = new MediaInfo();
|
|
786
|
|
mediaInfo.mMediaPlayerName = "ijkplayer";
|
|
787
|
|
|
|
788
|
|
String videoCodecInfo = _getVideoCodecInfo();
|
|
789
|
|
if (!TextUtils.isEmpty(videoCodecInfo)) {
|
|
790
|
|
String nodes[] = videoCodecInfo.split(",");
|
|
791
|
|
if (nodes.length >= 2) {
|
|
792
|
|
mediaInfo.mVideoDecoder = nodes[0];
|
|
793
|
|
mediaInfo.mVideoDecoderImpl = nodes[1];
|
|
794
|
|
} else if (nodes.length >= 1) {
|
|
795
|
|
mediaInfo.mVideoDecoder = nodes[0];
|
|
796
|
|
mediaInfo.mVideoDecoderImpl = "";
|
|
797
|
|
}
|
|
798
|
|
}
|
|
799
|
|
|
|
800
|
|
String audioCodecInfo = _getAudioCodecInfo();
|
|
801
|
|
if (!TextUtils.isEmpty(audioCodecInfo)) {
|
|
802
|
|
String nodes[] = audioCodecInfo.split(",");
|
|
803
|
|
if (nodes.length >= 2) {
|
|
804
|
|
mediaInfo.mAudioDecoder = nodes[0];
|
|
805
|
|
mediaInfo.mAudioDecoderImpl = nodes[1];
|
|
806
|
|
} else if (nodes.length >= 1) {
|
|
807
|
|
mediaInfo.mAudioDecoder = nodes[0];
|
|
808
|
|
mediaInfo.mAudioDecoderImpl = "";
|
|
809
|
|
}
|
|
810
|
|
}
|
|
811
|
|
|
|
812
|
|
try {
|
|
813
|
|
mediaInfo.mMeta = IjkMediaMeta.parse(_getMediaMeta());
|
|
814
|
|
} catch (Throwable e) {
|
|
815
|
|
e.printStackTrace();
|
|
816
|
|
}
|
|
817
|
|
return mediaInfo;
|
|
818
|
|
}
|
|
819
|
|
|
|
820
|
|
@Override
|
|
821
|
|
public void setLogEnabled(boolean enable) {
|
|
822
|
|
// do nothing
|
|
823
|
|
}
|
|
824
|
|
|
|
825
|
|
@Override
|
|
826
|
|
public boolean isPlayable() {
|
|
827
|
|
return true;
|
|
828
|
|
}
|
|
829
|
|
|
|
830
|
|
private native String _getVideoCodecInfo();
|
|
831
|
|
private native String _getAudioCodecInfo();
|
|
832
|
|
|
|
833
|
|
public void setOption(int category, String name, String value)
|
|
834
|
|
{
|
|
835
|
|
_setOption(category, name, value);
|
|
836
|
|
}
|
|
837
|
|
|
|
838
|
|
public void setOption(int category, String name, long value)
|
|
839
|
|
{
|
|
840
|
|
_setOption(category, name, value);
|
|
841
|
|
}
|
|
842
|
|
|
|
843
|
|
private native void _setOption(int category, String name, String value);
|
|
844
|
|
private native void _setOption(int category, String name, long value);
|
|
845
|
|
|
|
846
|
|
public Bundle getMediaMeta() {
|
|
847
|
|
return _getMediaMeta();
|
|
848
|
|
}
|
|
849
|
|
private native Bundle _getMediaMeta();
|
|
850
|
|
public native Bundle _getMetaData();
|
|
851
|
|
|
|
852
|
|
public static String getColorFormatName(int mediaCodecColorFormat) {
|
|
853
|
|
return _getColorFormatName(mediaCodecColorFormat);
|
|
854
|
|
}
|
|
855
|
|
|
|
856
|
|
private static native String _getColorFormatName(int mediaCodecColorFormat);
|
|
857
|
|
|
|
858
|
|
@Override
|
|
859
|
|
public void setAudioStreamType(int streamtype) {
|
|
860
|
|
// do nothing
|
|
861
|
|
}
|
|
862
|
|
|
|
863
|
|
@Override
|
|
864
|
|
public void setKeepInBackground(boolean keepInBackground) {
|
|
865
|
|
// do nothing
|
|
866
|
|
}
|
|
867
|
|
|
|
868
|
|
private static native void native_init();
|
|
869
|
|
|
|
870
|
|
private native void native_setup(Object IjkMediaPlayer_this);
|
|
871
|
|
|
|
872
|
|
private native void native_finalize();
|
|
873
|
|
|
|
874
|
|
private native void native_message_loop(Object IjkMediaPlayer_this);
|
|
875
|
|
|
|
876
|
|
protected void finalize() throws Throwable {
|
|
877
|
|
super.finalize();
|
|
878
|
|
native_finalize();
|
|
879
|
|
}
|
|
880
|
|
|
|
881
|
|
private static class EventHandler extends Handler {
|
|
882
|
|
private final WeakReference<IjkMediaPlayer> mWeakPlayer;
|
|
883
|
|
|
|
884
|
|
public EventHandler(IjkMediaPlayer mp, Looper looper) {
|
|
885
|
|
super(looper);
|
|
886
|
|
mWeakPlayer = new WeakReference<IjkMediaPlayer>(mp);
|
|
887
|
|
}
|
|
888
|
|
|
|
889
|
|
@Override
|
|
890
|
|
public void handleMessage(Message msg) {
|
|
891
|
|
IjkMediaPlayer player = mWeakPlayer.get();
|
|
892
|
|
if (player == null || player.mNativeMediaPlayer == 0) {
|
|
893
|
|
DebugLog.w(TAG,
|
|
894
|
|
"IjkMediaPlayer went away with unhandled events");
|
|
895
|
|
return;
|
|
896
|
|
}
|
|
897
|
|
|
|
898
|
|
switch (msg.what) {
|
|
899
|
|
case MEDIA_PREPARED:
|
|
900
|
|
player.notifyOnPrepared();
|
|
901
|
|
return;
|
|
902
|
|
|
|
903
|
|
case MEDIA_PLAYBACK_COMPLETE:
|
|
904
|
|
player.stayAwake(false);
|
|
905
|
|
player.notifyOnCompletion();
|
|
906
|
|
return;
|
|
907
|
|
|
|
908
|
|
case MEDIA_BUFFERING_UPDATE:
|
|
909
|
|
long bufferPosition = msg.arg1;
|
|
910
|
|
if (bufferPosition < 0) {
|
|
911
|
|
bufferPosition = 0;
|
|
912
|
|
}
|
|
913
|
|
|
|
914
|
|
long percent = 0;
|
|
915
|
|
long duration = player.getDuration();
|
|
916
|
|
if (duration > 0) {
|
|
917
|
|
percent = bufferPosition * 100 / duration;
|
|
918
|
|
}
|
|
919
|
|
if (percent >= 100) {
|
|
920
|
|
percent = 100;
|
|
921
|
|
}
|
|
922
|
|
|
|
923
|
|
// DebugLog.efmt(TAG, "Buffer (%d%%) %d/%d", percent, bufferPosition, duration);
|
|
924
|
|
player.notifyOnBufferingUpdate((int)percent);
|
|
925
|
|
return;
|
|
926
|
|
|
|
927
|
|
case MEDIA_SEEK_COMPLETE:
|
|
928
|
|
player.notifyOnSeekComplete();
|
|
929
|
|
return;
|
|
930
|
|
|
|
931
|
|
case MEDIA_SET_VIDEO_SIZE:
|
|
932
|
|
player.mVideoWidth = msg.arg1;
|
|
933
|
|
player.mVideoHeight = msg.arg2;
|
|
934
|
|
player.notifyOnVideoSizeChanged(player.mVideoWidth, player.mVideoHeight,
|
|
935
|
|
player.mVideoSarNum, player.mVideoSarDen);
|
|
936
|
|
return;
|
|
937
|
|
|
|
938
|
|
case MEDIA_ERROR:
|
|
939
|
|
DebugLog.e(TAG, "Error (" + msg.arg1 + "," + msg.arg2 + ")");
|
|
940
|
|
if (!player.notifyOnError(msg.arg1, msg.arg2)) {
|
|
941
|
|
player.notifyOnCompletion();
|
|
942
|
|
}
|
|
943
|
|
player.stayAwake(false);
|
|
944
|
|
return;
|
|
945
|
|
|
|
946
|
|
case MEDIA_INFO:
|
|
947
|
|
switch (msg.arg1) {
|
|
948
|
|
case MEDIA_INFO_VIDEO_RENDERING_START:
|
|
949
|
|
DebugLog.i(TAG, "Info: MEDIA_INFO_VIDEO_RENDERING_START\n");
|
|
950
|
|
break;
|
|
951
|
|
}
|
|
952
|
|
player.notifyOnInfo(msg.arg1, msg.arg2);
|
|
953
|
|
// No real default action so far.
|
|
954
|
|
return;
|
|
955
|
|
case MEDIA_TIMED_TEXT:
|
|
956
|
|
// do nothing
|
|
957
|
|
break;
|
|
958
|
|
|
|
959
|
|
case MEDIA_NOP: // interface test message - ignore
|
|
960
|
|
break;
|
|
961
|
|
|
|
962
|
|
case MEDIA_SET_VIDEO_SAR:
|
|
963
|
|
player.mVideoSarNum = msg.arg1;
|
|
964
|
|
player.mVideoSarDen = msg.arg2;
|
|
965
|
|
player.notifyOnVideoSizeChanged(player.mVideoWidth, player.mVideoHeight,
|
|
966
|
|
player.mVideoSarNum, player.mVideoSarDen);
|
|
967
|
|
break;
|
|
968
|
|
|
|
969
|
|
default:
|
|
970
|
|
DebugLog.e(TAG, "Unknown message type " + msg.what);
|
|
971
|
|
}
|
|
972
|
|
}
|
|
973
|
|
}
|
|
974
|
|
|
|
975
|
|
/*
|
|
976
|
|
* Called from native code when an interesting event happens. This method
|
|
977
|
|
* just uses the EventHandler system to post the event back to the main app
|
|
978
|
|
* thread. We use a weak reference to the original IjkMediaPlayer object so
|
|
979
|
|
* that the native code is safe from the object disappearing from underneath
|
|
980
|
|
* it. (This is the cookie passed to native_setup().)
|
|
981
|
|
*/
|
|
982
|
|
@CalledByNative
|
|
983
|
|
private static void postEventFromNative(Object weakThiz, int what,
|
|
984
|
|
int arg1, int arg2, Object obj) {
|
|
985
|
|
if (weakThiz == null)
|
|
986
|
|
return;
|
|
987
|
|
|
|
988
|
|
@SuppressWarnings("rawtypes")
|
|
989
|
|
IjkMediaPlayer mp = (IjkMediaPlayer) ((WeakReference) weakThiz).get();
|
|
990
|
|
if (mp == null) {
|
|
991
|
|
return;
|
|
992
|
|
}
|
|
993
|
|
|
|
994
|
|
if (what == MEDIA_INFO && arg1 == MEDIA_INFO_STARTED_AS_NEXT) {
|
|
995
|
|
// this acquires the wakelock if needed, and sets the client side
|
|
996
|
|
// state
|
|
997
|
|
mp.start();
|
|
998
|
|
}
|
|
999
|
|
if (mp.mEventHandler != null) {
|
|
1000
|
|
Message m = mp.mEventHandler.obtainMessage(what, arg1, arg2, obj);
|
|
1001
|
|
mp.mEventHandler.sendMessage(m);
|
|
1002
|
|
}
|
|
1003
|
|
}
|
|
1004
|
|
|
|
1005
|
|
/*
|
|
1006
|
|
* ControlMessage
|
|
1007
|
|
*/
|
|
1008
|
|
|
|
1009
|
|
private OnControlMessageListener mOnControlMessageListener;
|
|
1010
|
|
public void setOnControlMessageListener(OnControlMessageListener listener) {
|
|
1011
|
|
mOnControlMessageListener = listener;
|
|
1012
|
|
}
|
|
1013
|
|
|
|
1014
|
|
public interface OnControlMessageListener {
|
|
1015
|
|
String onControlResolveSegmentUrl(int segment);
|
|
1016
|
|
}
|
|
1017
|
|
|
|
1018
|
|
/*
|
|
1019
|
|
* NativeInvoke
|
|
1020
|
|
*/
|
|
1021
|
|
|
|
1022
|
|
private OnNativeInvokeListener mOnNativeInvokeListener;
|
|
1023
|
|
public void setOnNativeInvokeListener(OnNativeInvokeListener listener) {
|
|
1024
|
|
mOnNativeInvokeListener = listener;
|
|
1025
|
|
}
|
|
1026
|
|
|
|
1027
|
|
public interface OnNativeInvokeListener {
|
|
1028
|
|
int ON_CONCAT_RESOLVE_SEGMENT = 0x10000;
|
|
1029
|
|
int ON_TCP_OPEN = 0x10001;
|
|
1030
|
|
int ON_HTTP_OPEN = 0x10002;
|
|
1031
|
|
// int ON_HTTP_RETRY = 0x10003;
|
|
1032
|
|
int ON_LIVE_RETRY = 0x10004;
|
|
1033
|
|
|
|
1034
|
|
String ARG_URL = "url";
|
|
1035
|
|
String ARG_SEGMENT_INDEX = "segment_index";
|
|
1036
|
|
String ARG_RETRY_COUNTER = "retry_counter";
|
|
1037
|
|
|
|
1038
|
|
/*
|
|
1039
|
|
* @return true if invoke is handled
|
|
1040
|
|
* @throws Exception on any error
|
|
1041
|
|
*/
|
|
1042
|
|
boolean onNativeInvoke(int what, Bundle args);
|
|
1043
|
|
}
|
|
1044
|
|
|
|
1045
|
|
@CalledByNative
|
|
1046
|
|
private static boolean onNativeInvoke(Object weakThiz, int what, Bundle args) {
|
|
1047
|
|
DebugLog.ifmt(TAG, "onNativeInvoke %d", what);
|
|
1048
|
|
if (weakThiz == null || !(weakThiz instanceof WeakReference<?>))
|
|
1049
|
|
throw new IllegalStateException("<null weakThiz>.onNativeInvoke()");
|
|
1050
|
|
|
|
1051
|
|
@SuppressWarnings("unchecked")
|
|
1052
|
|
WeakReference<IjkMediaPlayer> weakPlayer = (WeakReference<IjkMediaPlayer>) weakThiz;
|
|
1053
|
|
IjkMediaPlayer player = weakPlayer.get();
|
|
1054
|
|
if (player == null)
|
|
1055
|
|
throw new IllegalStateException("<null weakPlayer>.onNativeInvoke()");
|
|
1056
|
|
|
|
1057
|
|
OnNativeInvokeListener listener = player.mOnNativeInvokeListener;
|
|
1058
|
|
if (listener != null && listener.onNativeInvoke(what, args))
|
|
1059
|
|
return true;
|
|
1060
|
|
|
|
1061
|
|
switch (what) {
|
|
1062
|
|
case OnNativeInvokeListener.ON_CONCAT_RESOLVE_SEGMENT: {
|
|
1063
|
|
OnControlMessageListener onControlMessageListener = player.mOnControlMessageListener;
|
|
1064
|
|
if (onControlMessageListener == null)
|
|
1065
|
|
return false;
|
|
1066
|
|
|
|
1067
|
|
int segmentIndex = args.getInt(OnNativeInvokeListener.ARG_SEGMENT_INDEX, -1);
|
|
1068
|
|
if (segmentIndex < 0)
|
|
1069
|
|
throw new InvalidParameterException("onNativeInvoke(invalid segment index)");
|
|
1070
|
|
|
|
1071
|
|
String newUrl = onControlMessageListener.onControlResolveSegmentUrl(segmentIndex);
|
|
1072
|
|
if (newUrl == null)
|
|
1073
|
|
throw new RuntimeException(new IOException("onNativeInvoke() = <NULL newUrl>"));
|
|
1074
|
|
|
|
1075
|
|
args.putString(OnNativeInvokeListener.ARG_URL, newUrl);
|
|
1076
|
|
return true;
|
|
1077
|
|
}
|
|
1078
|
|
default:
|
|
1079
|
|
return false;
|
|
1080
|
|
}
|
|
1081
|
|
}
|
|
1082
|
|
|
|
1083
|
|
/*
|
|
1084
|
|
* MediaCodec select
|
|
1085
|
|
*/
|
|
1086
|
|
|
|
1087
|
|
public interface OnMediaCodecSelectListener {
|
|
1088
|
|
String onMediaCodecSelect(IMediaPlayer mp, String mimeType, int profile, int level);
|
|
1089
|
|
}
|
|
1090
|
|
private OnMediaCodecSelectListener mOnMediaCodecSelectListener;
|
|
1091
|
|
public void setOnMediaCodecSelectListener(OnMediaCodecSelectListener listener) {
|
|
1092
|
|
mOnMediaCodecSelectListener = listener;
|
|
1093
|
|
}
|
|
1094
|
|
|
|
1095
|
|
public void resetListeners() {
|
|
1096
|
|
super.resetListeners();
|
|
1097
|
|
mOnMediaCodecSelectListener = null;
|
|
1098
|
|
}
|
|
1099
|
|
|
|
1100
|
|
@CalledByNative
|
|
1101
|
|
private static String onSelectCodec(Object weakThiz, String mimeType, int profile, int level) {
|
|
1102
|
|
if (weakThiz == null || !(weakThiz instanceof WeakReference<?>))
|
|
1103
|
|
return null;
|
|
1104
|
|
|
|
1105
|
|
@SuppressWarnings("unchecked")
|
|
1106
|
|
WeakReference<IjkMediaPlayer> weakPlayer = (WeakReference<IjkMediaPlayer>) weakThiz;
|
|
1107
|
|
IjkMediaPlayer player = weakPlayer.get();
|
|
1108
|
|
if (player == null)
|
|
1109
|
|
return null;
|
|
1110
|
|
|
|
1111
|
|
OnMediaCodecSelectListener listener = player.mOnMediaCodecSelectListener;
|
|
1112
|
|
if (listener == null)
|
|
1113
|
|
listener = DefaultMediaCodecSelector.sInstance;
|
|
1114
|
|
|
|
1115
|
|
return listener.onMediaCodecSelect(player, mimeType, profile, level);
|
|
1116
|
|
}
|
|
1117
|
|
|
|
1118
|
|
public static class DefaultMediaCodecSelector implements OnMediaCodecSelectListener {
|
|
1119
|
|
public static final DefaultMediaCodecSelector sInstance = new DefaultMediaCodecSelector();
|
|
1120
|
|
|
|
1121
|
|
@SuppressWarnings("deprecation")
|
|
1122
|
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
1123
|
|
public String onMediaCodecSelect(IMediaPlayer mp, String mimeType, int profile, int level) {
|
|
1124
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
|
|
1125
|
|
return null;
|
|
1126
|
|
|
|
1127
|
|
if (TextUtils.isEmpty(mimeType))
|
|
1128
|
|
return null;
|
|
1129
|
|
|
|
1130
|
|
Log.i(TAG, String.format(Locale.US, "onSelectCodec: mime=%s, profile=%d, level=%d", mimeType, profile, level));
|
|
1131
|
|
ArrayList<IjkMediaCodecInfo> candidateCodecList = new ArrayList<IjkMediaCodecInfo>();
|
|
1132
|
|
int numCodecs = MediaCodecList.getCodecCount();
|
|
1133
|
|
for (int i = 0; i < numCodecs; i++) {
|
|
1134
|
|
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
|
|
1135
|
|
Log.d(TAG, String.format(Locale.US, " found codec: %s", codecInfo.getName()));
|
|
1136
|
|
if (codecInfo.isEncoder())
|
|
1137
|
|
continue;
|
|
1138
|
|
|
|
1139
|
|
String[] types = codecInfo.getSupportedTypes();
|
|
1140
|
|
if (types == null)
|
|
1141
|
|
continue;
|
|
1142
|
|
|
|
1143
|
|
for(String type: types) {
|
|
1144
|
|
if (TextUtils.isEmpty(type))
|
|
1145
|
|
continue;
|
|
1146
|
|
|
|
1147
|
|
Log.d(TAG, String.format(Locale.US, " mime: %s", type));
|
|
1148
|
|
if (!type.equalsIgnoreCase(mimeType))
|
|
1149
|
|
continue;
|
|
1150
|
|
|
|
1151
|
|
IjkMediaCodecInfo candidate = IjkMediaCodecInfo.setupCandidate(codecInfo, mimeType);
|
|
1152
|
|
if (candidate == null)
|
|
1153
|
|
continue;
|
|
1154
|
|
|
|
1155
|
|
candidateCodecList.add(candidate);
|
|
1156
|
|
Log.i(TAG, String.format(Locale.US, "candidate codec: %s rank=%d", codecInfo.getName(), candidate.mRank));
|
|
1157
|
|
candidate.dumpProfileLevels(mimeType);
|
|
1158
|
|
}
|
|
1159
|
|
}
|
|
1160
|
|
|
|
1161
|
|
if (candidateCodecList.isEmpty()) {
|
|
1162
|
|
return null;
|
|
1163
|
|
}
|
|
1164
|
|
|
|
1165
|
|
IjkMediaCodecInfo bestCodec = candidateCodecList.get(0);
|
|
1166
|
|
|
|
1167
|
|
for (IjkMediaCodecInfo codec : candidateCodecList) {
|
|
1168
|
|
if (codec.mRank > bestCodec.mRank) {
|
|
1169
|
|
bestCodec = codec;
|
|
1170
|
|
}
|
|
1171
|
|
}
|
|
1172
|
|
|
|
1173
|
|
if (bestCodec.mRank < IjkMediaCodecInfo.RANK_LAST_CHANCE) {
|
|
1174
|
|
Log.w(TAG, String.format(Locale.US, "unaccetable codec: %s", bestCodec.mCodecInfo.getName()));
|
|
1175
|
|
return null;
|
|
1176
|
|
}
|
|
1177
|
|
|
|
1178
|
|
Log.i(TAG, String.format(Locale.US, "selected codec: %s rank=%d", bestCodec.mCodecInfo.getName(), bestCodec.mRank));
|
|
1179
|
|
return bestCodec.mCodecInfo.getName();
|
|
1180
|
|
}
|
|
1181
|
|
}
|
|
1182
|
|
|
|
1183
|
|
public static native void native_profileBegin(String libName);
|
|
1184
|
|
public static native void native_profileEnd();
|
|
1185
|
|
public static native void native_setLogLevel(int level);
|
|
1186
|
|
|
|
1187
|
|
private native void _setAudioDataCallback();
|
|
1188
|
|
private native void _delAudioDataCallback();
|
|
1189
|
|
|
|
1190
|
|
private OnAudioDataCallback mAudioDataCallback = null;
|
|
1191
|
|
|
|
1192
|
|
public void setOnAudioDataCallback(OnAudioDataCallback callback) {
|
|
1193
|
|
if (callback != null) {
|
|
1194
|
|
this.mAudioDataCallback = callback;
|
|
1195
|
|
_setAudioDataCallback();
|
|
1196
|
|
} else {
|
|
1197
|
|
this.mAudioDataCallback = null;
|
|
1198
|
|
_delAudioDataCallback();
|
|
1199
|
|
}
|
|
1200
|
|
}
|
|
1201
|
|
|
|
1202
|
|
public interface OnAudioDataCallback {
|
|
1203
|
|
void onAudioData(byte[] audio_data, int len);
|
|
1204
|
|
}
|
|
1205
|
|
|
|
1206
|
|
// audio data callback
|
|
1207
|
|
public void audioCallback(byte[] audio_data, int data_size) {
|
|
1208
|
|
if (mAudioDataCallback != null) {
|
|
1209
|
|
mAudioDataCallback.onAudioData(audio_data, data_size);
|
|
1210
|
|
}
|
|
1211
|
|
}
|
|
1212
|
|
}
|
|
|
@ -1,29 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2013-2014 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player;
|
|
18
|
|
|
|
19
|
|
public class MediaInfo {
|
|
20
|
|
public String mMediaPlayerName;
|
|
21
|
|
|
|
22
|
|
public String mVideoDecoder;
|
|
23
|
|
public String mVideoDecoderImpl;
|
|
24
|
|
|
|
25
|
|
public String mAudioDecoder;
|
|
26
|
|
public String mAudioDecoderImpl;
|
|
27
|
|
|
|
28
|
|
public IjkMediaMeta mMeta;
|
|
29
|
|
}
|
|
|
@ -1,323 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player;
|
|
18
|
|
|
|
19
|
|
import android.annotation.TargetApi;
|
|
20
|
|
import android.content.Context;
|
|
21
|
|
import android.net.Uri;
|
|
22
|
|
import android.os.Build;
|
|
23
|
|
import android.view.Surface;
|
|
24
|
|
import android.view.SurfaceHolder;
|
|
25
|
|
|
|
26
|
|
import java.io.FileDescriptor;
|
|
27
|
|
import java.io.IOException;
|
|
28
|
|
import java.util.Map;
|
|
29
|
|
|
|
30
|
|
import tv.danmaku.ijk.media.player.misc.IMediaDataSource;
|
|
31
|
|
import tv.danmaku.ijk.media.player.misc.ITrackInfo;
|
|
32
|
|
|
|
33
|
|
public class MediaPlayerProxy implements IMediaPlayer {
|
|
34
|
|
protected final IMediaPlayer mBackEndMediaPlayer;
|
|
35
|
|
|
|
36
|
|
public MediaPlayerProxy(IMediaPlayer backEndMediaPlayer) {
|
|
37
|
|
mBackEndMediaPlayer = backEndMediaPlayer;
|
|
38
|
|
}
|
|
39
|
|
|
|
40
|
|
public IMediaPlayer getInternalMediaPlayer() {
|
|
41
|
|
return mBackEndMediaPlayer;
|
|
42
|
|
}
|
|
43
|
|
|
|
44
|
|
@Override
|
|
45
|
|
public void setDisplay(SurfaceHolder sh) {
|
|
46
|
|
mBackEndMediaPlayer.setDisplay(sh);
|
|
47
|
|
}
|
|
48
|
|
|
|
49
|
|
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
|
50
|
|
@Override
|
|
51
|
|
public void setSurface(Surface surface) {
|
|
52
|
|
mBackEndMediaPlayer.setSurface(surface);
|
|
53
|
|
}
|
|
54
|
|
|
|
55
|
|
@Override
|
|
56
|
|
public void setDataSource(Context context, Uri uri)
|
|
57
|
|
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
|
|
58
|
|
mBackEndMediaPlayer.setDataSource(context, uri);
|
|
59
|
|
}
|
|
60
|
|
|
|
61
|
|
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
|
62
|
|
@Override
|
|
63
|
|
public void setDataSource(Context context, Uri uri, Map<String, String> headers)
|
|
64
|
|
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
|
|
65
|
|
mBackEndMediaPlayer.setDataSource(context, uri, headers);
|
|
66
|
|
}
|
|
67
|
|
|
|
68
|
|
@Override
|
|
69
|
|
public void setDataSource(FileDescriptor fd)
|
|
70
|
|
throws IOException, IllegalArgumentException, IllegalStateException {
|
|
71
|
|
mBackEndMediaPlayer.setDataSource(fd);
|
|
72
|
|
}
|
|
73
|
|
|
|
74
|
|
@Override
|
|
75
|
|
public void setDataSource(String path) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
|
|
76
|
|
mBackEndMediaPlayer.setDataSource(path);
|
|
77
|
|
}
|
|
78
|
|
|
|
79
|
|
@Override
|
|
80
|
|
public void setDataSource(IMediaDataSource mediaDataSource) {
|
|
81
|
|
mBackEndMediaPlayer.setDataSource(mediaDataSource);
|
|
82
|
|
}
|
|
83
|
|
|
|
84
|
|
@Override
|
|
85
|
|
public String getDataSource() {
|
|
86
|
|
return mBackEndMediaPlayer.getDataSource();
|
|
87
|
|
}
|
|
88
|
|
|
|
89
|
|
@Override
|
|
90
|
|
public void prepareAsync() throws IllegalStateException {
|
|
91
|
|
mBackEndMediaPlayer.prepareAsync();
|
|
92
|
|
}
|
|
93
|
|
|
|
94
|
|
@Override
|
|
95
|
|
public void start() throws IllegalStateException {
|
|
96
|
|
mBackEndMediaPlayer.start();
|
|
97
|
|
}
|
|
98
|
|
|
|
99
|
|
@Override
|
|
100
|
|
public void stop() throws IllegalStateException {
|
|
101
|
|
mBackEndMediaPlayer.stop();
|
|
102
|
|
}
|
|
103
|
|
|
|
104
|
|
@Override
|
|
105
|
|
public void pause() throws IllegalStateException {
|
|
106
|
|
mBackEndMediaPlayer.pause();
|
|
107
|
|
}
|
|
108
|
|
|
|
109
|
|
@Override
|
|
110
|
|
public void setScreenOnWhilePlaying(boolean screenOn) {
|
|
111
|
|
mBackEndMediaPlayer.setScreenOnWhilePlaying(screenOn);
|
|
112
|
|
}
|
|
113
|
|
|
|
114
|
|
@Override
|
|
115
|
|
public int getVideoWidth() {
|
|
116
|
|
return mBackEndMediaPlayer.getVideoWidth();
|
|
117
|
|
}
|
|
118
|
|
|
|
119
|
|
@Override
|
|
120
|
|
public int getVideoHeight() {
|
|
121
|
|
return mBackEndMediaPlayer.getVideoHeight();
|
|
122
|
|
}
|
|
123
|
|
|
|
124
|
|
@Override
|
|
125
|
|
public boolean isPlaying() {
|
|
126
|
|
return mBackEndMediaPlayer.isPlaying();
|
|
127
|
|
}
|
|
128
|
|
|
|
129
|
|
@Override
|
|
130
|
|
public void seekTo(long msec) throws IllegalStateException {
|
|
131
|
|
mBackEndMediaPlayer.seekTo(msec);
|
|
132
|
|
}
|
|
133
|
|
|
|
134
|
|
@Override
|
|
135
|
|
public long getCurrentPosition() {
|
|
136
|
|
return mBackEndMediaPlayer.getCurrentPosition();
|
|
137
|
|
}
|
|
138
|
|
|
|
139
|
|
@Override
|
|
140
|
|
public long getDuration() {
|
|
141
|
|
return mBackEndMediaPlayer.getDuration();
|
|
142
|
|
}
|
|
143
|
|
|
|
144
|
|
@Override
|
|
145
|
|
public void release() {
|
|
146
|
|
mBackEndMediaPlayer.release();
|
|
147
|
|
}
|
|
148
|
|
|
|
149
|
|
@Override
|
|
150
|
|
public void reset() {
|
|
151
|
|
mBackEndMediaPlayer.reset();
|
|
152
|
|
}
|
|
153
|
|
|
|
154
|
|
@Override
|
|
155
|
|
public void setVolume(float leftVolume, float rightVolume) {
|
|
156
|
|
mBackEndMediaPlayer.setVolume(leftVolume, rightVolume);
|
|
157
|
|
}
|
|
158
|
|
|
|
159
|
|
@Override
|
|
160
|
|
public int getAudioSessionId() {
|
|
161
|
|
return mBackEndMediaPlayer.getAudioSessionId();
|
|
162
|
|
}
|
|
163
|
|
|
|
164
|
|
@Override
|
|
165
|
|
public MediaInfo getMediaInfo() {
|
|
166
|
|
return mBackEndMediaPlayer.getMediaInfo();
|
|
167
|
|
}
|
|
168
|
|
|
|
169
|
|
@Override
|
|
170
|
|
public void setLogEnabled(boolean enable) {
|
|
171
|
|
|
|
172
|
|
}
|
|
173
|
|
|
|
174
|
|
@Override
|
|
175
|
|
public boolean isPlayable() {
|
|
176
|
|
return false;
|
|
177
|
|
}
|
|
178
|
|
|
|
179
|
|
@Override
|
|
180
|
|
public void setOnPreparedListener(OnPreparedListener listener) {
|
|
181
|
|
if (listener != null) {
|
|
182
|
|
final OnPreparedListener finalListener = listener;
|
|
183
|
|
mBackEndMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
|
|
184
|
|
@Override
|
|
185
|
|
public void onPrepared(IMediaPlayer mp) {
|
|
186
|
|
finalListener.onPrepared(MediaPlayerProxy.this);
|
|
187
|
|
}
|
|
188
|
|
});
|
|
189
|
|
} else {
|
|
190
|
|
mBackEndMediaPlayer.setOnPreparedListener(null);
|
|
191
|
|
}
|
|
192
|
|
}
|
|
193
|
|
|
|
194
|
|
@Override
|
|
195
|
|
public void setOnCompletionListener(OnCompletionListener listener) {
|
|
196
|
|
if (listener != null) {
|
|
197
|
|
final OnCompletionListener finalListener = listener;
|
|
198
|
|
mBackEndMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
|
|
199
|
|
@Override
|
|
200
|
|
public void onCompletion(IMediaPlayer mp) {
|
|
201
|
|
finalListener.onCompletion(MediaPlayerProxy.this);
|
|
202
|
|
}
|
|
203
|
|
});
|
|
204
|
|
} else {
|
|
205
|
|
mBackEndMediaPlayer.setOnCompletionListener(null);
|
|
206
|
|
}
|
|
207
|
|
}
|
|
208
|
|
|
|
209
|
|
@Override
|
|
210
|
|
public void setOnBufferingUpdateListener(OnBufferingUpdateListener listener) {
|
|
211
|
|
if (listener != null) {
|
|
212
|
|
final OnBufferingUpdateListener finalListener = listener;
|
|
213
|
|
mBackEndMediaPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
|
|
214
|
|
@Override
|
|
215
|
|
public void onBufferingUpdate(IMediaPlayer mp, int percent) {
|
|
216
|
|
finalListener.onBufferingUpdate(MediaPlayerProxy.this, percent);
|
|
217
|
|
}
|
|
218
|
|
});
|
|
219
|
|
} else {
|
|
220
|
|
mBackEndMediaPlayer.setOnBufferingUpdateListener(null);
|
|
221
|
|
}
|
|
222
|
|
}
|
|
223
|
|
|
|
224
|
|
@Override
|
|
225
|
|
public void setOnSeekCompleteListener(OnSeekCompleteListener listener) {
|
|
226
|
|
if (listener != null) {
|
|
227
|
|
final OnSeekCompleteListener finalListener = listener;
|
|
228
|
|
mBackEndMediaPlayer.setOnSeekCompleteListener(new OnSeekCompleteListener() {
|
|
229
|
|
@Override
|
|
230
|
|
public void onSeekComplete(IMediaPlayer mp) {
|
|
231
|
|
finalListener.onSeekComplete(MediaPlayerProxy.this);
|
|
232
|
|
}
|
|
233
|
|
});
|
|
234
|
|
} else {
|
|
235
|
|
mBackEndMediaPlayer.setOnSeekCompleteListener(null);
|
|
236
|
|
}
|
|
237
|
|
}
|
|
238
|
|
|
|
239
|
|
@Override
|
|
240
|
|
public void setOnVideoSizeChangedListener(OnVideoSizeChangedListener listener) {
|
|
241
|
|
if (listener != null) {
|
|
242
|
|
final OnVideoSizeChangedListener finalListener = listener;
|
|
243
|
|
mBackEndMediaPlayer.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
|
|
244
|
|
@Override
|
|
245
|
|
public void onVideoSizeChanged(IMediaPlayer mp, int width, int height, int sar_num, int sar_den) {
|
|
246
|
|
finalListener.onVideoSizeChanged(MediaPlayerProxy.this, width, height, sar_num, sar_den);
|
|
247
|
|
}
|
|
248
|
|
});
|
|
249
|
|
} else {
|
|
250
|
|
mBackEndMediaPlayer.setOnVideoSizeChangedListener(null);
|
|
251
|
|
}
|
|
252
|
|
}
|
|
253
|
|
|
|
254
|
|
@Override
|
|
255
|
|
public void setOnErrorListener(OnErrorListener listener) {
|
|
256
|
|
if (listener != null) {
|
|
257
|
|
final OnErrorListener finalListener = listener;
|
|
258
|
|
mBackEndMediaPlayer.setOnErrorListener(new OnErrorListener() {
|
|
259
|
|
@Override
|
|
260
|
|
public boolean onError(IMediaPlayer mp, int what, int extra) {
|
|
261
|
|
return finalListener.onError(MediaPlayerProxy.this, what, extra);
|
|
262
|
|
}
|
|
263
|
|
});
|
|
264
|
|
} else {
|
|
265
|
|
mBackEndMediaPlayer.setOnErrorListener(null);
|
|
266
|
|
}
|
|
267
|
|
}
|
|
268
|
|
|
|
269
|
|
@Override
|
|
270
|
|
public void setOnInfoListener(OnInfoListener listener) {
|
|
271
|
|
if (listener != null) {
|
|
272
|
|
final OnInfoListener finalListener = listener;
|
|
273
|
|
mBackEndMediaPlayer.setOnInfoListener(new OnInfoListener() {
|
|
274
|
|
@Override
|
|
275
|
|
public boolean onInfo(IMediaPlayer mp, int what, int extra) {
|
|
276
|
|
return finalListener.onInfo(MediaPlayerProxy.this, what, extra);
|
|
277
|
|
}
|
|
278
|
|
});
|
|
279
|
|
} else {
|
|
280
|
|
mBackEndMediaPlayer.setOnInfoListener(null);
|
|
281
|
|
}
|
|
282
|
|
}
|
|
283
|
|
|
|
284
|
|
@Override
|
|
285
|
|
public void setAudioStreamType(int streamtype) {
|
|
286
|
|
mBackEndMediaPlayer.setAudioStreamType(streamtype);
|
|
287
|
|
}
|
|
288
|
|
|
|
289
|
|
@Override
|
|
290
|
|
public void setKeepInBackground(boolean keepInBackground) {
|
|
291
|
|
mBackEndMediaPlayer.setKeepInBackground(keepInBackground);
|
|
292
|
|
}
|
|
293
|
|
|
|
294
|
|
@Override
|
|
295
|
|
public int getVideoSarNum() {
|
|
296
|
|
return mBackEndMediaPlayer.getVideoSarNum();
|
|
297
|
|
}
|
|
298
|
|
|
|
299
|
|
@Override
|
|
300
|
|
public int getVideoSarDen() {
|
|
301
|
|
return mBackEndMediaPlayer.getVideoSarDen();
|
|
302
|
|
}
|
|
303
|
|
|
|
304
|
|
@Override
|
|
305
|
|
public void setWakeMode(Context context, int mode) {
|
|
306
|
|
mBackEndMediaPlayer.setWakeMode(context, mode);
|
|
307
|
|
}
|
|
308
|
|
|
|
309
|
|
@Override
|
|
310
|
|
public ITrackInfo[] getTrackInfo() {
|
|
311
|
|
return mBackEndMediaPlayer.getTrackInfo();
|
|
312
|
|
}
|
|
313
|
|
|
|
314
|
|
@Override
|
|
315
|
|
public void setLooping(boolean looping) {
|
|
316
|
|
mBackEndMediaPlayer.setLooping(looping);
|
|
317
|
|
}
|
|
318
|
|
|
|
319
|
|
@Override
|
|
320
|
|
public boolean isLooping() {
|
|
321
|
|
return mBackEndMediaPlayer.isLooping();
|
|
322
|
|
}
|
|
323
|
|
}
|
|
|
@ -1,99 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player;
|
|
18
|
|
|
|
19
|
|
import android.annotation.TargetApi;
|
|
20
|
|
import android.graphics.SurfaceTexture;
|
|
21
|
|
import android.os.Build;
|
|
22
|
|
import android.view.Surface;
|
|
23
|
|
import android.view.SurfaceHolder;
|
|
24
|
|
|
|
25
|
|
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
|
26
|
|
public class TextureMediaPlayer extends MediaPlayerProxy implements IMediaPlayer, ISurfaceTextureHolder {
|
|
27
|
|
private SurfaceTexture mSurfaceTexture;
|
|
28
|
|
private ISurfaceTextureHost mSurfaceTextureHost;
|
|
29
|
|
|
|
30
|
|
public TextureMediaPlayer(IMediaPlayer backEndMediaPlayer) {
|
|
31
|
|
super(backEndMediaPlayer);
|
|
32
|
|
}
|
|
33
|
|
|
|
34
|
|
public void releaseSurfaceTexture() {
|
|
35
|
|
if (mSurfaceTexture != null) {
|
|
36
|
|
if (mSurfaceTextureHost != null) {
|
|
37
|
|
mSurfaceTextureHost.releaseSurfaceTexture(mSurfaceTexture);
|
|
38
|
|
} else {
|
|
39
|
|
mSurfaceTexture.release();
|
|
40
|
|
}
|
|
41
|
|
mSurfaceTexture = null;
|
|
42
|
|
}
|
|
43
|
|
}
|
|
44
|
|
|
|
45
|
|
//--------------------
|
|
46
|
|
// IMediaPlayer
|
|
47
|
|
//--------------------
|
|
48
|
|
@Override
|
|
49
|
|
public void reset() {
|
|
50
|
|
super.reset();
|
|
51
|
|
releaseSurfaceTexture();
|
|
52
|
|
}
|
|
53
|
|
|
|
54
|
|
@Override
|
|
55
|
|
public void release() {
|
|
56
|
|
super.release();
|
|
57
|
|
releaseSurfaceTexture();
|
|
58
|
|
}
|
|
59
|
|
|
|
60
|
|
@Override
|
|
61
|
|
public void setDisplay(SurfaceHolder sh) {
|
|
62
|
|
if (mSurfaceTexture == null)
|
|
63
|
|
super.setDisplay(sh);
|
|
64
|
|
}
|
|
65
|
|
|
|
66
|
|
@Override
|
|
67
|
|
public void setSurface(Surface surface) {
|
|
68
|
|
if (mSurfaceTexture == null)
|
|
69
|
|
super.setSurface(surface);
|
|
70
|
|
}
|
|
71
|
|
|
|
72
|
|
//--------------------
|
|
73
|
|
// ISurfaceTextureHolder
|
|
74
|
|
//--------------------
|
|
75
|
|
|
|
76
|
|
@Override
|
|
77
|
|
public void setSurfaceTexture(SurfaceTexture surfaceTexture) {
|
|
78
|
|
if (mSurfaceTexture == surfaceTexture)
|
|
79
|
|
return;
|
|
80
|
|
|
|
81
|
|
releaseSurfaceTexture();
|
|
82
|
|
mSurfaceTexture = surfaceTexture;
|
|
83
|
|
if (surfaceTexture == null) {
|
|
84
|
|
super.setSurface(null);
|
|
85
|
|
} else {
|
|
86
|
|
super.setSurface(new Surface(surfaceTexture));
|
|
87
|
|
}
|
|
88
|
|
}
|
|
89
|
|
|
|
90
|
|
@Override
|
|
91
|
|
public SurfaceTexture getSurfaceTexture() {
|
|
92
|
|
return mSurfaceTexture;
|
|
93
|
|
}
|
|
94
|
|
|
|
95
|
|
@Override
|
|
96
|
|
public void setSurfaceTextureHost(ISurfaceTextureHost surfaceTextureHost) {
|
|
97
|
|
mSurfaceTextureHost = surfaceTextureHost;
|
|
98
|
|
}
|
|
99
|
|
}
|
|
|
@ -1,31 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2013-2014 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player.annotations;
|
|
18
|
|
|
|
19
|
|
import java.lang.annotation.ElementType;
|
|
20
|
|
import java.lang.annotation.Retention;
|
|
21
|
|
import java.lang.annotation.RetentionPolicy;
|
|
22
|
|
import java.lang.annotation.Target;
|
|
23
|
|
|
|
24
|
|
/**
|
|
25
|
|
* is used by the JNI generator to create the necessary JNI
|
|
26
|
|
* bindings and expose this method to native code.
|
|
27
|
|
*/
|
|
28
|
|
@Target(ElementType.FIELD)
|
|
29
|
|
@Retention(RetentionPolicy.CLASS)
|
|
30
|
|
public @interface AccessedByNative {
|
|
31
|
|
}
|
|
|
@ -1,35 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2013-2014 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player.annotations;
|
|
18
|
|
|
|
19
|
|
import java.lang.annotation.ElementType;
|
|
20
|
|
import java.lang.annotation.Retention;
|
|
21
|
|
import java.lang.annotation.RetentionPolicy;
|
|
22
|
|
import java.lang.annotation.Target;
|
|
23
|
|
|
|
24
|
|
/**
|
|
25
|
|
* is used by the JNI generator to create the necessary JNI
|
|
26
|
|
* bindings and expose this method to native code.
|
|
27
|
|
*/
|
|
28
|
|
@Target(ElementType.METHOD)
|
|
29
|
|
@Retention(RetentionPolicy.CLASS)
|
|
30
|
|
public @interface CalledByNative {
|
|
31
|
|
/*
|
|
32
|
|
* If present, tells which inner class the method belongs to.
|
|
33
|
|
*/
|
|
34
|
|
String value() default "";
|
|
35
|
|
}
|
|
|
@ -1,21 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2013-2014 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player.exceptions;
|
|
18
|
|
|
|
19
|
|
public class IjkMediaException extends Exception {
|
|
20
|
|
private static final long serialVersionUID = 7234796519009099506L;
|
|
21
|
|
}
|
|
|
@ -1,5 +0,0 @@
|
|
1
|
|
package tv.danmaku.ijk.media.player.ffmpeg;
|
|
2
|
|
|
|
3
|
|
public class FFmpegApi {
|
|
4
|
|
public static native String av_base64_encode(byte in[]);
|
|
5
|
|
}
|
|
|
@ -1,62 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player.misc;
|
|
18
|
|
|
|
19
|
|
import android.annotation.TargetApi;
|
|
20
|
|
import android.media.MediaFormat;
|
|
21
|
|
import android.os.Build;
|
|
22
|
|
|
|
23
|
|
public class AndroidMediaFormat implements IMediaFormat {
|
|
24
|
|
private final MediaFormat mMediaFormat;
|
|
25
|
|
|
|
26
|
|
public AndroidMediaFormat(MediaFormat mediaFormat) {
|
|
27
|
|
mMediaFormat = mediaFormat;
|
|
28
|
|
}
|
|
29
|
|
|
|
30
|
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
31
|
|
@Override
|
|
32
|
|
public int getInteger(String name) {
|
|
33
|
|
if (mMediaFormat == null)
|
|
34
|
|
return 0;
|
|
35
|
|
|
|
36
|
|
return mMediaFormat.getInteger(name);
|
|
37
|
|
}
|
|
38
|
|
|
|
39
|
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
40
|
|
@Override
|
|
41
|
|
public String getString(String name) {
|
|
42
|
|
if (mMediaFormat == null)
|
|
43
|
|
return null;
|
|
44
|
|
|
|
45
|
|
return mMediaFormat.getString(name);
|
|
46
|
|
}
|
|
47
|
|
|
|
48
|
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
49
|
|
@Override
|
|
50
|
|
public String toString() {
|
|
51
|
|
StringBuilder out = new StringBuilder(128);
|
|
52
|
|
out.append(getClass().getName());
|
|
53
|
|
out.append('{');
|
|
54
|
|
if (mMediaFormat != null) {
|
|
55
|
|
out.append(mMediaFormat.toString());
|
|
56
|
|
} else {
|
|
57
|
|
out.append("null");
|
|
58
|
|
}
|
|
59
|
|
out.append('}');
|
|
60
|
|
return out.toString();
|
|
61
|
|
}
|
|
62
|
|
}
|
|
|
@ -1,108 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player.misc;
|
|
18
|
|
|
|
19
|
|
import android.annotation.TargetApi;
|
|
20
|
|
import android.media.MediaFormat;
|
|
21
|
|
import android.media.MediaPlayer;
|
|
22
|
|
import android.os.Build;
|
|
23
|
|
|
|
24
|
|
public class AndroidTrackInfo implements ITrackInfo {
|
|
25
|
|
private final MediaPlayer.TrackInfo mTrackInfo;
|
|
26
|
|
|
|
27
|
|
public static AndroidTrackInfo[] fromMediaPlayer(MediaPlayer mp) {
|
|
28
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
|
|
29
|
|
return fromTrackInfo(mp.getTrackInfo());
|
|
30
|
|
|
|
31
|
|
return null;
|
|
32
|
|
}
|
|
33
|
|
|
|
34
|
|
private static AndroidTrackInfo[] fromTrackInfo(MediaPlayer.TrackInfo[] trackInfos) {
|
|
35
|
|
if (trackInfos == null)
|
|
36
|
|
return null;
|
|
37
|
|
|
|
38
|
|
AndroidTrackInfo androidTrackInfo[] = new AndroidTrackInfo[trackInfos.length];
|
|
39
|
|
for (int i = 0; i < trackInfos.length; ++i) {
|
|
40
|
|
androidTrackInfo[i] = new AndroidTrackInfo(trackInfos[i]);
|
|
41
|
|
}
|
|
42
|
|
|
|
43
|
|
return androidTrackInfo;
|
|
44
|
|
}
|
|
45
|
|
|
|
46
|
|
private AndroidTrackInfo(MediaPlayer.TrackInfo trackInfo) {
|
|
47
|
|
mTrackInfo = trackInfo;
|
|
48
|
|
}
|
|
49
|
|
|
|
50
|
|
@TargetApi(Build.VERSION_CODES.KITKAT)
|
|
51
|
|
@Override
|
|
52
|
|
public IMediaFormat getFormat() {
|
|
53
|
|
if (mTrackInfo == null)
|
|
54
|
|
return null;
|
|
55
|
|
|
|
56
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
|
|
57
|
|
return null;
|
|
58
|
|
|
|
59
|
|
MediaFormat mediaFormat = mTrackInfo.getFormat();
|
|
60
|
|
if (mediaFormat == null)
|
|
61
|
|
return null;
|
|
62
|
|
|
|
63
|
|
return new AndroidMediaFormat(mediaFormat);
|
|
64
|
|
}
|
|
65
|
|
|
|
66
|
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
67
|
|
@Override
|
|
68
|
|
public String getLanguage() {
|
|
69
|
|
if (mTrackInfo == null)
|
|
70
|
|
return "und";
|
|
71
|
|
|
|
72
|
|
return mTrackInfo.getLanguage();
|
|
73
|
|
}
|
|
74
|
|
|
|
75
|
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
76
|
|
@Override
|
|
77
|
|
public int getTrackType() {
|
|
78
|
|
if (mTrackInfo == null)
|
|
79
|
|
return MEDIA_TRACK_TYPE_UNKNOWN;
|
|
80
|
|
|
|
81
|
|
return mTrackInfo.getTrackType();
|
|
82
|
|
}
|
|
83
|
|
|
|
84
|
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
85
|
|
@Override
|
|
86
|
|
public String toString() {
|
|
87
|
|
StringBuilder out = new StringBuilder(128);
|
|
88
|
|
out.append(getClass().getSimpleName());
|
|
89
|
|
out.append('{');
|
|
90
|
|
if (mTrackInfo != null) {
|
|
91
|
|
out.append(mTrackInfo.toString());
|
|
92
|
|
} else {
|
|
93
|
|
out.append("null");
|
|
94
|
|
}
|
|
95
|
|
out.append('}');
|
|
96
|
|
return out.toString();
|
|
97
|
|
}
|
|
98
|
|
|
|
99
|
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
100
|
|
@Override
|
|
101
|
|
public String getInfoInline() {
|
|
102
|
|
if (mTrackInfo != null) {
|
|
103
|
|
return mTrackInfo.toString();
|
|
104
|
|
} else {
|
|
105
|
|
return "null";
|
|
106
|
|
}
|
|
107
|
|
}
|
|
108
|
|
}
|
|
|
@ -1,28 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player.misc;
|
|
18
|
|
|
|
19
|
|
import java.io.IOException;
|
|
20
|
|
|
|
21
|
|
@SuppressWarnings("RedundantThrows")
|
|
22
|
|
public interface IMediaDataSource {
|
|
23
|
|
int readAt(long position, byte[] buffer, int offset, int size) throws IOException;
|
|
24
|
|
|
|
25
|
|
long getSize() throws IOException;
|
|
26
|
|
|
|
27
|
|
void close() throws IOException;
|
|
28
|
|
}
|
|
|
@ -1,30 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player.misc;
|
|
18
|
|
|
|
19
|
|
public interface IMediaFormat {
|
|
20
|
|
// Common keys
|
|
21
|
|
String KEY_MIME = "mime";
|
|
22
|
|
|
|
23
|
|
// Video Keys
|
|
24
|
|
String KEY_WIDTH = "width";
|
|
25
|
|
String KEY_HEIGHT = "height";
|
|
26
|
|
|
|
27
|
|
String getString(String name);
|
|
28
|
|
|
|
29
|
|
int getInteger(String name);
|
|
30
|
|
}
|
|
|
@ -1,34 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player.misc;
|
|
18
|
|
|
|
19
|
|
public interface ITrackInfo {
|
|
20
|
|
int MEDIA_TRACK_TYPE_AUDIO = 2;
|
|
21
|
|
int MEDIA_TRACK_TYPE_METADATA = 5;
|
|
22
|
|
int MEDIA_TRACK_TYPE_SUBTITLE = 4;
|
|
23
|
|
int MEDIA_TRACK_TYPE_TIMEDTEXT = 3;
|
|
24
|
|
int MEDIA_TRACK_TYPE_UNKNOWN = 0;
|
|
25
|
|
int MEDIA_TRACK_TYPE_VIDEO = 1;
|
|
26
|
|
|
|
27
|
|
IMediaFormat getFormat();
|
|
28
|
|
|
|
29
|
|
String getLanguage();
|
|
30
|
|
|
|
31
|
|
int getTrackType();
|
|
32
|
|
|
|
33
|
|
String getInfoInline();
|
|
34
|
|
}
|
|
|
@ -1,209 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player.misc;
|
|
18
|
|
|
|
19
|
|
import android.annotation.TargetApi;
|
|
20
|
|
import android.os.Build;
|
|
21
|
|
import android.text.TextUtils;
|
|
22
|
|
|
|
23
|
|
import java.util.HashMap;
|
|
24
|
|
import java.util.Locale;
|
|
25
|
|
import java.util.Map;
|
|
26
|
|
|
|
27
|
|
import tv.danmaku.ijk.media.player.IjkMediaMeta;
|
|
28
|
|
|
|
29
|
|
public class IjkMediaFormat implements IMediaFormat {
|
|
30
|
|
// Common
|
|
31
|
|
public static final String KEY_IJK_CODEC_LONG_NAME_UI = "ijk-codec-long-name-ui";
|
|
32
|
|
public static final String KEY_IJK_BIT_RATE_UI = "ijk-bit-rate-ui";
|
|
33
|
|
|
|
34
|
|
// Video
|
|
35
|
|
public static final String KEY_IJK_CODEC_PROFILE_LEVEL_UI = "ijk-profile-level-ui";
|
|
36
|
|
public static final String KEY_IJK_CODEC_PIXEL_FORMAT_UI = "ijk-pixel-format-ui";
|
|
37
|
|
public static final String KEY_IJK_RESOLUTION_UI = "ijk-resolution-ui";
|
|
38
|
|
public static final String KEY_IJK_FRAME_RATE_UI = "ijk-frame-rate-ui";
|
|
39
|
|
|
|
40
|
|
// Audio
|
|
41
|
|
public static final String KEY_IJK_SAMPLE_RATE_UI = "ijk-sample-rate-ui";
|
|
42
|
|
public static final String KEY_IJK_CHANNEL_UI = "ijk-channel-ui";
|
|
43
|
|
|
|
44
|
|
// Codec
|
|
45
|
|
public static final String CODEC_NAME_H264 = "h264";
|
|
46
|
|
|
|
47
|
|
public final IjkMediaMeta.IjkStreamMeta mMediaFormat;
|
|
48
|
|
|
|
49
|
|
public IjkMediaFormat(IjkMediaMeta.IjkStreamMeta streamMeta) {
|
|
50
|
|
mMediaFormat = streamMeta;
|
|
51
|
|
}
|
|
52
|
|
|
|
53
|
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
54
|
|
@Override
|
|
55
|
|
public int getInteger(String name) {
|
|
56
|
|
if (mMediaFormat == null)
|
|
57
|
|
return 0;
|
|
58
|
|
|
|
59
|
|
return mMediaFormat.getInt(name);
|
|
60
|
|
}
|
|
61
|
|
|
|
62
|
|
@Override
|
|
63
|
|
public String getString(String name) {
|
|
64
|
|
if (mMediaFormat == null)
|
|
65
|
|
return null;
|
|
66
|
|
|
|
67
|
|
if (sFormatterMap.containsKey(name)) {
|
|
68
|
|
Formatter formatter = sFormatterMap.get(name);
|
|
69
|
|
return formatter.format(this);
|
|
70
|
|
}
|
|
71
|
|
|
|
72
|
|
return mMediaFormat.getString(name);
|
|
73
|
|
}
|
|
74
|
|
|
|
75
|
|
//-------------------------
|
|
76
|
|
// Formatter
|
|
77
|
|
//-------------------------
|
|
78
|
|
|
|
79
|
|
private static abstract class Formatter {
|
|
80
|
|
public String format(IjkMediaFormat mediaFormat) {
|
|
81
|
|
String value = doFormat(mediaFormat);
|
|
82
|
|
if (TextUtils.isEmpty(value))
|
|
83
|
|
return getDefaultString();
|
|
84
|
|
return value;
|
|
85
|
|
}
|
|
86
|
|
|
|
87
|
|
protected abstract String doFormat(IjkMediaFormat mediaFormat);
|
|
88
|
|
|
|
89
|
|
@SuppressWarnings("SameReturnValue")
|
|
90
|
|
protected String getDefaultString() {
|
|
91
|
|
return "N/A";
|
|
92
|
|
}
|
|
93
|
|
}
|
|
94
|
|
|
|
95
|
|
private static final Map<String, Formatter> sFormatterMap = new HashMap<String, Formatter>();
|
|
96
|
|
|
|
97
|
|
{
|
|
98
|
|
sFormatterMap.put(KEY_IJK_CODEC_LONG_NAME_UI, new Formatter() {
|
|
99
|
|
@Override
|
|
100
|
|
public String doFormat(IjkMediaFormat mediaFormat) {
|
|
101
|
|
return mMediaFormat.getString(IjkMediaMeta.IJKM_KEY_CODEC_LONG_NAME);
|
|
102
|
|
}
|
|
103
|
|
});
|
|
104
|
|
sFormatterMap.put(KEY_IJK_BIT_RATE_UI, new Formatter() {
|
|
105
|
|
@Override
|
|
106
|
|
protected String doFormat(IjkMediaFormat mediaFormat) {
|
|
107
|
|
int bitRate = mediaFormat.getInteger(IjkMediaMeta.IJKM_KEY_BITRATE);
|
|
108
|
|
if (bitRate <= 0) {
|
|
109
|
|
return null;
|
|
110
|
|
} else if (bitRate < 1000) {
|
|
111
|
|
return String.format(Locale.US, "%d bit/s", bitRate);
|
|
112
|
|
} else {
|
|
113
|
|
return String.format(Locale.US, "%d kb/s", bitRate / 1000);
|
|
114
|
|
}
|
|
115
|
|
}
|
|
116
|
|
});
|
|
117
|
|
sFormatterMap.put(KEY_IJK_CODEC_PROFILE_LEVEL_UI, new Formatter() {
|
|
118
|
|
@Override
|
|
119
|
|
protected String doFormat(IjkMediaFormat mediaFormat) {
|
|
120
|
|
String profile = mediaFormat.getString(IjkMediaMeta.IJKM_KEY_CODEC_PROFILE);
|
|
121
|
|
if (TextUtils.isEmpty(profile))
|
|
122
|
|
return null;
|
|
123
|
|
|
|
124
|
|
StringBuilder sb = new StringBuilder();
|
|
125
|
|
sb.append(profile);
|
|
126
|
|
|
|
127
|
|
String codecName = mediaFormat.getString(IjkMediaMeta.IJKM_KEY_CODEC_NAME);
|
|
128
|
|
if (!TextUtils.isEmpty(codecName) && codecName.equalsIgnoreCase(CODEC_NAME_H264)) {
|
|
129
|
|
int level = mediaFormat.getInteger(IjkMediaMeta.IJKM_KEY_CODEC_LEVEL);
|
|
130
|
|
if (level < 10)
|
|
131
|
|
return sb.toString();
|
|
132
|
|
|
|
133
|
|
sb.append(" Profile Level ");
|
|
134
|
|
sb.append((level / 10) % 10);
|
|
135
|
|
if ((level % 10) != 0) {
|
|
136
|
|
sb.append(".");
|
|
137
|
|
sb.append(level % 10);
|
|
138
|
|
}
|
|
139
|
|
}
|
|
140
|
|
|
|
141
|
|
return sb.toString();
|
|
142
|
|
}
|
|
143
|
|
});
|
|
144
|
|
sFormatterMap.put(KEY_IJK_CODEC_PIXEL_FORMAT_UI, new Formatter() {
|
|
145
|
|
@Override
|
|
146
|
|
protected String doFormat(IjkMediaFormat mediaFormat) {
|
|
147
|
|
return mediaFormat.getString(IjkMediaMeta.IJKM_KEY_CODEC_PIXEL_FORMAT);
|
|
148
|
|
}
|
|
149
|
|
});
|
|
150
|
|
sFormatterMap.put(KEY_IJK_RESOLUTION_UI, new Formatter() {
|
|
151
|
|
@Override
|
|
152
|
|
protected String doFormat(IjkMediaFormat mediaFormat) {
|
|
153
|
|
int width = mediaFormat.getInteger(KEY_WIDTH);
|
|
154
|
|
int height = mediaFormat.getInteger(KEY_HEIGHT);
|
|
155
|
|
int sarNum = mediaFormat.getInteger(IjkMediaMeta.IJKM_KEY_SAR_NUM);
|
|
156
|
|
int sarDen = mediaFormat.getInteger(IjkMediaMeta.IJKM_KEY_SAR_DEN);
|
|
157
|
|
|
|
158
|
|
if (width <= 0 || height <= 0) {
|
|
159
|
|
return null;
|
|
160
|
|
} else if (sarNum <= 0 || sarDen <= 0) {
|
|
161
|
|
return String.format(Locale.US, "%d x %d", width, height);
|
|
162
|
|
} else {
|
|
163
|
|
return String.format(Locale.US, "%d x %d [SAR %d:%d]", width,
|
|
164
|
|
height, sarNum, sarDen);
|
|
165
|
|
}
|
|
166
|
|
}
|
|
167
|
|
});
|
|
168
|
|
sFormatterMap.put(KEY_IJK_FRAME_RATE_UI, new Formatter() {
|
|
169
|
|
@Override
|
|
170
|
|
protected String doFormat(IjkMediaFormat mediaFormat) {
|
|
171
|
|
int fpsNum = mediaFormat.getInteger(IjkMediaMeta.IJKM_KEY_FPS_NUM);
|
|
172
|
|
int fpsDen = mediaFormat.getInteger(IjkMediaMeta.IJKM_KEY_FPS_DEN);
|
|
173
|
|
if (fpsNum <= 0 || fpsDen <= 0) {
|
|
174
|
|
return null;
|
|
175
|
|
} else {
|
|
176
|
|
return String.valueOf(((float) (fpsNum)) / fpsDen);
|
|
177
|
|
}
|
|
178
|
|
}
|
|
179
|
|
});
|
|
180
|
|
sFormatterMap.put(KEY_IJK_SAMPLE_RATE_UI, new Formatter() {
|
|
181
|
|
@Override
|
|
182
|
|
protected String doFormat(IjkMediaFormat mediaFormat) {
|
|
183
|
|
int sampleRate = mediaFormat.getInteger(IjkMediaMeta.IJKM_KEY_SAMPLE_RATE);
|
|
184
|
|
if (sampleRate <= 0) {
|
|
185
|
|
return null;
|
|
186
|
|
} else {
|
|
187
|
|
return String.format(Locale.US, "%d Hz", sampleRate);
|
|
188
|
|
}
|
|
189
|
|
}
|
|
190
|
|
});
|
|
191
|
|
sFormatterMap.put(KEY_IJK_CHANNEL_UI, new Formatter() {
|
|
192
|
|
@Override
|
|
193
|
|
protected String doFormat(IjkMediaFormat mediaFormat) {
|
|
194
|
|
int channelLayout = mediaFormat.getInteger(IjkMediaMeta.IJKM_KEY_CHANNEL_LAYOUT);
|
|
195
|
|
if (channelLayout <= 0) {
|
|
196
|
|
return null;
|
|
197
|
|
} else {
|
|
198
|
|
if (channelLayout == IjkMediaMeta.AV_CH_LAYOUT_MONO) {
|
|
199
|
|
return "mono";
|
|
200
|
|
} else if (channelLayout == IjkMediaMeta.AV_CH_LAYOUT_STEREO) {
|
|
201
|
|
return "stereo";
|
|
202
|
|
} else {
|
|
203
|
|
return String.format(Locale.US, "%x", channelLayout);
|
|
204
|
|
}
|
|
205
|
|
}
|
|
206
|
|
}
|
|
207
|
|
});
|
|
208
|
|
}
|
|
209
|
|
}
|
|
|
@ -1,96 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player.misc;
|
|
18
|
|
|
|
19
|
|
import android.text.TextUtils;
|
|
20
|
|
|
|
21
|
|
import tv.danmaku.ijk.media.player.IjkMediaMeta;
|
|
22
|
|
|
|
23
|
|
public class IjkTrackInfo implements ITrackInfo {
|
|
24
|
|
private int mTrackType = MEDIA_TRACK_TYPE_UNKNOWN;
|
|
25
|
|
private IjkMediaMeta.IjkStreamMeta mStreamMeta;
|
|
26
|
|
|
|
27
|
|
public IjkTrackInfo(IjkMediaMeta.IjkStreamMeta streamMeta) {
|
|
28
|
|
mStreamMeta = streamMeta;
|
|
29
|
|
}
|
|
30
|
|
|
|
31
|
|
public void setMediaMeta(IjkMediaMeta.IjkStreamMeta streamMeta) {
|
|
32
|
|
mStreamMeta = streamMeta;
|
|
33
|
|
}
|
|
34
|
|
|
|
35
|
|
@Override
|
|
36
|
|
public IMediaFormat getFormat() {
|
|
37
|
|
return new IjkMediaFormat(mStreamMeta);
|
|
38
|
|
}
|
|
39
|
|
|
|
40
|
|
@Override
|
|
41
|
|
public String getLanguage() {
|
|
42
|
|
if (mStreamMeta == null || TextUtils.isEmpty(mStreamMeta.mLanguage))
|
|
43
|
|
return "und";
|
|
44
|
|
|
|
45
|
|
return mStreamMeta.mLanguage;
|
|
46
|
|
}
|
|
47
|
|
|
|
48
|
|
@Override
|
|
49
|
|
public int getTrackType() {
|
|
50
|
|
return mTrackType;
|
|
51
|
|
}
|
|
52
|
|
|
|
53
|
|
public void setTrackType(int trackType) {
|
|
54
|
|
mTrackType = trackType;
|
|
55
|
|
}
|
|
56
|
|
|
|
57
|
|
@Override
|
|
58
|
|
public String toString() {
|
|
59
|
|
return getClass().getSimpleName() + '{' + getInfoInline() + "}";
|
|
60
|
|
}
|
|
61
|
|
|
|
62
|
|
@Override
|
|
63
|
|
public String getInfoInline() {
|
|
64
|
|
StringBuilder out = new StringBuilder(128);
|
|
65
|
|
switch (mTrackType) {
|
|
66
|
|
case MEDIA_TRACK_TYPE_VIDEO:
|
|
67
|
|
out.append("VIDEO");
|
|
68
|
|
out.append(", ");
|
|
69
|
|
out.append(mStreamMeta.getCodecShortNameInline());
|
|
70
|
|
out.append(", ");
|
|
71
|
|
out.append(mStreamMeta.getBitrateInline());
|
|
72
|
|
out.append(", ");
|
|
73
|
|
out.append(mStreamMeta.getResolutionInline());
|
|
74
|
|
break;
|
|
75
|
|
case MEDIA_TRACK_TYPE_AUDIO:
|
|
76
|
|
out.append("AUDIO");
|
|
77
|
|
out.append(", ");
|
|
78
|
|
out.append(mStreamMeta.getCodecShortNameInline());
|
|
79
|
|
out.append(", ");
|
|
80
|
|
out.append(mStreamMeta.getBitrateInline());
|
|
81
|
|
out.append(", ");
|
|
82
|
|
out.append(mStreamMeta.getSampleRateInline());
|
|
83
|
|
break;
|
|
84
|
|
case MEDIA_TRACK_TYPE_TIMEDTEXT:
|
|
85
|
|
out.append("TIMEDTEXT");
|
|
86
|
|
break;
|
|
87
|
|
case MEDIA_TRACK_TYPE_SUBTITLE:
|
|
88
|
|
out.append("SUBTITLE");
|
|
89
|
|
break;
|
|
90
|
|
default:
|
|
91
|
|
out.append("UNKNOWN");
|
|
92
|
|
break;
|
|
93
|
|
}
|
|
94
|
|
return out.toString();
|
|
95
|
|
}
|
|
96
|
|
}
|
|
|
@ -1,142 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2013 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
|
|
17
|
|
package tv.danmaku.ijk.media.player.pragma;
|
|
18
|
|
|
|
19
|
|
import java.util.Locale;
|
|
20
|
|
|
|
21
|
|
|
|
22
|
|
import android.util.Log;
|
|
23
|
|
|
|
24
|
|
@SuppressWarnings({"SameParameterValue", "WeakerAccess"})
|
|
25
|
|
public class DebugLog {
|
|
26
|
|
public static final boolean ENABLE_ERROR = Pragma.ENABLE_VERBOSE;
|
|
27
|
|
public static final boolean ENABLE_INFO = Pragma.ENABLE_VERBOSE;
|
|
28
|
|
public static final boolean ENABLE_WARN = Pragma.ENABLE_VERBOSE;
|
|
29
|
|
public static final boolean ENABLE_DEBUG = Pragma.ENABLE_VERBOSE;
|
|
30
|
|
public static final boolean ENABLE_VERBOSE = Pragma.ENABLE_VERBOSE;
|
|
31
|
|
|
|
32
|
|
public static void e(String tag, String msg) {
|
|
33
|
|
if (ENABLE_ERROR) {
|
|
34
|
|
Log.e(tag, msg);
|
|
35
|
|
}
|
|
36
|
|
}
|
|
37
|
|
|
|
38
|
|
public static void e(String tag, String msg, Throwable tr) {
|
|
39
|
|
if (ENABLE_ERROR) {
|
|
40
|
|
Log.e(tag, msg, tr);
|
|
41
|
|
}
|
|
42
|
|
}
|
|
43
|
|
|
|
44
|
|
public static void efmt(String tag, String fmt, Object... args) {
|
|
45
|
|
if (ENABLE_ERROR) {
|
|
46
|
|
String msg = String.format(Locale.US, fmt, args);
|
|
47
|
|
Log.e(tag, msg);
|
|
48
|
|
}
|
|
49
|
|
}
|
|
50
|
|
|
|
51
|
|
public static void i(String tag, String msg) {
|
|
52
|
|
if (ENABLE_INFO) {
|
|
53
|
|
Log.i(tag, msg);
|
|
54
|
|
}
|
|
55
|
|
}
|
|
56
|
|
|
|
57
|
|
public static void i(String tag, String msg, Throwable tr) {
|
|
58
|
|
if (ENABLE_INFO) {
|
|
59
|
|
Log.i(tag, msg, tr);
|
|
60
|
|
}
|
|
61
|
|
}
|
|
62
|
|
|
|
63
|
|
public static void ifmt(String tag, String fmt, Object... args) {
|
|
64
|
|
if (ENABLE_INFO) {
|
|
65
|
|
String msg = String.format(Locale.US, fmt, args);
|
|
66
|
|
Log.i(tag, msg);
|
|
67
|
|
}
|
|
68
|
|
}
|
|
69
|
|
|
|
70
|
|
public static void w(String tag, String msg) {
|
|
71
|
|
if (ENABLE_WARN) {
|
|
72
|
|
Log.w(tag, msg);
|
|
73
|
|
}
|
|
74
|
|
}
|
|
75
|
|
|
|
76
|
|
public static void w(String tag, String msg, Throwable tr) {
|
|
77
|
|
if (ENABLE_WARN) {
|
|
78
|
|
Log.w(tag, msg, tr);
|
|
79
|
|
}
|
|
80
|
|
}
|
|
81
|
|
|
|
82
|
|
public static void wfmt(String tag, String fmt, Object... args) {
|
|
83
|
|
if (ENABLE_WARN) {
|
|
84
|
|
String msg = String.format(Locale.US, fmt, args);
|
|
85
|
|
Log.w(tag, msg);
|
|
86
|
|
}
|
|
87
|
|
}
|
|
88
|
|
|
|
89
|
|
public static void d(String tag, String msg) {
|
|
90
|
|
if (ENABLE_DEBUG) {
|
|
91
|
|
Log.d(tag, msg);
|
|
92
|
|
}
|
|
93
|
|
}
|
|
94
|
|
|
|
95
|
|
public static void d(String tag, String msg, Throwable tr) {
|
|
96
|
|
if (ENABLE_DEBUG) {
|
|
97
|
|
Log.d(tag, msg, tr);
|
|
98
|
|
}
|
|
99
|
|
}
|
|
100
|
|
|
|
101
|
|
public static void dfmt(String tag, String fmt, Object... args) {
|
|
102
|
|
if (ENABLE_DEBUG) {
|
|
103
|
|
String msg = String.format(Locale.US, fmt, args);
|
|
104
|
|
Log.d(tag, msg);
|
|
105
|
|
}
|
|
106
|
|
}
|
|
107
|
|
|
|
108
|
|
public static void v(String tag, String msg) {
|
|
109
|
|
if (ENABLE_VERBOSE) {
|
|
110
|
|
Log.v(tag, msg);
|
|
111
|
|
}
|
|
112
|
|
}
|
|
113
|
|
|
|
114
|
|
public static void v(String tag, String msg, Throwable tr) {
|
|
115
|
|
if (ENABLE_VERBOSE) {
|
|
116
|
|
Log.v(tag, msg, tr);
|
|
117
|
|
}
|
|
118
|
|
}
|
|
119
|
|
|
|
120
|
|
public static void vfmt(String tag, String fmt, Object... args) {
|
|
121
|
|
if (ENABLE_VERBOSE) {
|
|
122
|
|
String msg = String.format(Locale.US, fmt, args);
|
|
123
|
|
Log.v(tag, msg);
|
|
124
|
|
}
|
|
125
|
|
}
|
|
126
|
|
|
|
127
|
|
public static void printStackTrace(Throwable e) {
|
|
128
|
|
if (ENABLE_WARN) {
|
|
129
|
|
e.printStackTrace();
|
|
130
|
|
}
|
|
131
|
|
}
|
|
132
|
|
|
|
133
|
|
public static void printCause(Throwable e) {
|
|
134
|
|
if (ENABLE_WARN) {
|
|
135
|
|
Throwable cause = e.getCause();
|
|
136
|
|
if (cause != null)
|
|
137
|
|
e = cause;
|
|
138
|
|
|
|
139
|
|
printStackTrace(e);
|
|
140
|
|
}
|
|
141
|
|
}
|
|
142
|
|
}
|
|
|
@ -1,23 +0,0 @@
|
|
1
|
|
/*
|
|
2
|
|
* Copyright (C) 2013 Zhang Rui <bbcallen@gmail.com>
|
|
3
|
|
*
|
|
4
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
|
* you may not use this file except in compliance with the License.
|
|
6
|
|
* You may obtain a copy of the License at
|
|
7
|
|
*
|
|
8
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
|
*
|
|
10
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
|
* See the License for the specific language governing permissions and
|
|
14
|
|
* limitations under the License.
|
|
15
|
|
*/
|
|
16
|
|
package tv.danmaku.ijk.media.player.pragma;
|
|
17
|
|
|
|
18
|
|
/*-
|
|
19
|
|
* configurated by app project
|
|
20
|
|
*/
|
|
21
|
|
public class Pragma {
|
|
22
|
|
public static final boolean ENABLE_VERBOSE = true;
|
|
23
|
|
}
|
|
|
@ -1,15 +0,0 @@
|
|
1
|
|
# This file is automatically generated by Android Tools.
|
|
2
|
|
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
|
3
|
|
#
|
|
4
|
|
# This file must be checked in Version Control Systems.
|
|
5
|
|
#
|
|
6
|
|
# To customize properties used by the Ant build system edit
|
|
7
|
|
# "ant.properties", and override values to adapt the script to your
|
|
8
|
|
# project structure.
|
|
9
|
|
#
|
|
10
|
|
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
|
11
|
|
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
|
12
|
|
|
|
13
|
|
# Project target.
|
|
14
|
|
target=android-22
|
|
15
|
|
android.library=true
|
|
|
@ -1,6 +0,0 @@
|
|
1
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
|
<resources>
|
|
3
|
|
|
|
4
|
|
<string name="ijkplayer_dummy"></string>
|
|
5
|
|
|
|
6
|
|
</resources>
|
|
|
@ -1,2 +1,2 @@
|
|
1
|
|
include ':app', ':autolayout', ':zxing', ':XRefreshView', ':ijkplayer-java',':library'
|
|
|
1
|
include ':app', ':autolayout', ':zxing', ':XRefreshView',':library'
|
|
2
|
2
|
include ':videolibrary:picture_library', ':videolibrary:SmallVideoLib2'
|