Skip to content

Commit

Permalink
Merge branch 'release-0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
befovy committed Aug 25, 2019
2 parents 8729fde + 05346b3 commit 9f853ec
Show file tree
Hide file tree
Showing 37 changed files with 1,437 additions and 457 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
## next
--------------------------------

## 0.1.0
- update ijkplauer to f0.3.5
- fijkplayer err state and FijkException
- support playing flutter asset file
- unit test and widget test
- pass fijkoption arguments and set player's option

## 0.0.9
--------------------------------
- update ijkplayer to f0.3.4
Expand Down
4 changes: 2 additions & 2 deletions README.en.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# fijkplayer (Video player plugin for Flutter)


[![pub package](https://img.shields.io/pub/v/fijkplayer.svg)](https://pub.dartlang.org/packages/fijkplayer)    
[![Build Status](https://travis-ci.org/befovy/fijkplayer.svg?branch=master)](https://travis-ci.org/befovy/fijkplayer)    

Expand All @@ -9,7 +10,6 @@ A Flutter media player plugin for iOS and android based on [ijkplayer](https://g
*Read this in other languages: [English](README.en.md), [简体中文](README.zh-cn.md).*


*Note*: This plugin is still under development, and some APIs might not be available yet.
[Feedback welcome](https://github.com/befovy/fijkplayer/issues) and
[Pull Requests](https://github.com/befovy/fijkplayer/pulls) are most welcome!

Expand All @@ -19,7 +19,7 @@ Add `fijkplayer` as a [dependency in your pubspec.yaml file](https://flutter.io/

```yaml
dependencies:
fijkplayer: ^0.0.6
fijkplayer: ^0.1.0
```
Expand Down
1 change: 0 additions & 1 deletion README.md

This file was deleted.

95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# fijkplayer (Video player plugin for Flutter)


[![pub package](https://img.shields.io/pub/v/fijkplayer.svg)](https://pub.dartlang.org/packages/fijkplayer)    
[![Build Status](https://travis-ci.org/befovy/fijkplayer.svg?branch=master)](https://travis-ci.org/befovy/fijkplayer)    

A Flutter media player plugin for iOS and android based on [ijkplayer](https://github.com/befovy/ijkplayer)


*Read this in other languages: [English](README.en.md), [简体中文](README.zh-cn.md).*


[Feedback welcome](https://github.com/befovy/fijkplayer/issues) and
[Pull Requests](https://github.com/befovy/fijkplayer/pulls) are most welcome!

## Installation

Add `fijkplayer` as a [dependency in your pubspec.yaml file](https://flutter.io/using-packages/).

```yaml
dependencies:
fijkplayer: ^0.1.0
```
## Example
```dart
import 'package:fijkplayer/fijkplayer.dart';
import 'package:flutter/material.dart';

class VideoScreen extends StatefulWidget {
final String url;

VideoScreen({@required this.url});

@override
_VideoScreenState createState() => _VideoScreenState();
}

class _VideoScreenState extends State<VideoScreen> {
final FijkPlayer player = FijkPlayer();

_VideoScreenState();

@override
void initState() {
super.initState();
player.setDataSource(widget.url, autoPlay: true);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Fijkplayer Example")),
body: Container(
alignment: Alignment.center,
child: FijkView(
player: player,
),
));
}

@override
void dispose() {
super.dispose();
player.release();
}
}

```

## Demo Screenshots

iOS screenshots
<div>
<img src="https://user-images.githubusercontent.com/51129600/61178868-abefcc00-a629-11e9-851f-f4b2ab0028fb.jpeg" height="300px" alt="ios_input" >
&nbsp; &nbsp; &nbsp;
<img src="https://user-images.githubusercontent.com/51129600/61178869-abefcc00-a629-11e9-8b15-872d8cd207b9.jpeg" height="300px" alt="ios_video" >
</div>

android screenshots

<div>
<img src="https://user-images.githubusercontent.com/51129600/61178866-ab573580-a629-11e9-8019-77a400998531.jpeg" height="300px" alt="android_home" >
&nbsp; &nbsp; &nbsp;
<img src="https://user-images.githubusercontent.com/51129600/61178867-ab573580-a629-11e9-8829-8a37efb39d7d.jpeg" height="300px" alt="android_video" >
</div>



## iOS Warning

Warning: The fijkplayer video player plugin is not functional on iOS simulators. An iOS device must be used during development/testing. For more details, please refer to this [issue](https://github.com/flutter/flutter/issues/14647).

5 changes: 2 additions & 3 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

```yaml
dependencies:
fijkplayer: ^0.0.9
fijkplayer: ^0.1.0
```
## 基础用法
Expand Down Expand Up @@ -111,8 +111,7 @@ pod 'FIJKPlayer'
```gradle
dependencies {
// fijkplayer-full include the java lib and native shared libs for armv5 armv7 arm64 x86 x86_64
implementation 'com.befovy.fijkplayer:fijkplayer-full:0.3.4'
implementation 'com.befovy.fijkplayer:fijkplayer-full:0.3.4'
implementation 'com.befovy.fijkplayer:fijkplayer-full:0.3.5'
}
```

Expand Down
1 change: 1 addition & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.DS_Store
/build
/captures
/aars
8 changes: 7 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ android {
lintOptions {
disable 'InvalidPackage'
}

aaptOptions {
noCompress '.flv', '.mp4'
}

}


dependencies {

// implementation(name: 'fijkplayer-full-release', ext: 'aar')

// fijkplayer-full include the java lib and native shared libs for armv5 armv7 arm64 x86 x86_64
implementation 'com.befovy.fijkplayer:fijkplayer-full:0.3.4'
implementation 'com.befovy.fijkplayer:fijkplayer-full:0.3.5'
implementation 'com.android.support:support-annotations:28.0.0'
}
48 changes: 38 additions & 10 deletions android/src/main/java/com/befovy/fijkplayer/FijkPlayer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.befovy.fijkplayer;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.graphics.SurfaceTexture;
import android.net.Uri;
Expand All @@ -12,7 +11,9 @@
import androidx.annotation.NonNull;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -30,7 +31,22 @@ public class FijkPlayer implements MethodChannel.MethodCallHandler, IjkEventList

final private static AtomicInteger atomicId = new AtomicInteger(0);

final private static int idle = 0;
final private static int initialized = 1;
final private static int asyncPreparing = 2;
@SuppressWarnings("unused")
final private static int prepared = 3;
@SuppressWarnings("unused")
final private static int started = 4;
final private static int paused = 5;
final private static int completed = 6;
final private static int stopped = 7;
@SuppressWarnings("unused")
final private static int error = 8;
final private static int end = 9;

final private int mPlayerId;
private int mState;
final private IjkMediaPlayer mIjkMediaPlayer;
final private Context mContext;

Expand All @@ -53,6 +69,7 @@ public class FijkPlayer implements MethodChannel.MethodCallHandler, IjkEventList
FijkPlayer(PluginRegistry.Registrar registrar) {
mRegistrar = registrar;
mPlayerId = atomicId.incrementAndGet();
mState = 0;
mIjkMediaPlayer = new IjkMediaPlayer();
mIjkMediaPlayer.addIjkEventListener(this);

Expand Down Expand Up @@ -93,9 +110,8 @@ long setupSurface() {
}

void release() {
mIjkMediaPlayer.stop();
handleEvent(PLAYBACK_STATE_CHANGED, end, mState, null);
mIjkMediaPlayer.release();

if (mSurfaceTextureEntry != null) {
mSurfaceTextureEntry.release();
mSurfaceTextureEntry = null;
Expand All @@ -121,6 +137,7 @@ private void handleEvent(int what, int arg1, int arg2, Object extra) {
mEventSink.success(event);
break;
case PLAYBACK_STATE_CHANGED:
mState = arg1;
event.put("event", "state_change");
event.put("new", arg1);
event.put("old", arg2);
Expand Down Expand Up @@ -151,6 +168,9 @@ private void handleEvent(int what, int arg1, int arg2, Object extra) {
event.put("height", arg2);
mEventSink.success(event);
break;
case ERROR:
mEventSink.error(String.valueOf(arg1), extra.toString(), arg2);
break;
default:
// Log.d("FLUTTER", "jonEvent:" + what);
break;
Expand All @@ -166,6 +186,7 @@ public void onEvent(IjkMediaPlayer ijkMediaPlayer, int what, int arg1, int arg2,
case BUFFERING_END:
case BUFFERING_UPDATE:
case VIDEO_SIZE_CHANGED:
case ERROR:
handleEvent(what, arg1, arg2, extra);
break;
default:
Expand Down Expand Up @@ -200,6 +221,7 @@ private void applyOptions(Object options) {

@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
//noinspection IfCanBeSwitch
if (call.method.equals("setupSurface")) {
long viewId = setupSurface();
result.success(viewId);
Expand All @@ -223,7 +245,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
String url = call.argument("url");
Uri uri = Uri.parse(url);
boolean openAsset = false;
if ("assets".equals(uri.getScheme())) {
if ("asset".equals(uri.getScheme())) {
openAsset = true;
String host = uri.getHost();
String path = uri.getPath() != null ? uri.getPath().substring(1) : "";
Expand All @@ -237,9 +259,8 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
try {
if (openAsset) {
AssetManager assetManager = mRegistrar.context().getAssets();
AssetFileDescriptor fd = assetManager.openFd(uri.getPath() != null ? uri.getPath() : "");
//mIjkMediaPlayer.setDataSource(fd.getFileDescriptor());
mIjkMediaPlayer.setDataSource(new RawMediaDataSource(fd, mRegistrar.context(), uri.getPath()));
InputStream is = assetManager.open(uri.getPath() != null ? uri.getPath() : "", AssetManager.ACCESS_RANDOM);
mIjkMediaPlayer.setDataSource(new RawMediaDataSource(is));
} else {
if (TextUtils.isEmpty(uri.getScheme()) || "file".equals(uri.getScheme())) {
IMediaDataSource dataSource = new FileMediaDataSource(new File(uri.toString()));
Expand All @@ -248,12 +269,16 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
mIjkMediaPlayer.setDataSource(mContext, uri);
}
}
handleEvent(PLAYBACK_STATE_CHANGED, initialized, -1, null);
result.success(null);
} catch (FileNotFoundException e) {
result.error("-875574348", "Local File not found:" + e.getMessage(), null);
} catch (IOException e) {
result.error(e.getMessage(), null, null);
result.error("-1162824012", "Local IOException:" + e.getMessage(), null);
}
} else if (call.method.equals("prepareAsync")) {
mIjkMediaPlayer.prepareAsync();
handleEvent(PLAYBACK_STATE_CHANGED, asyncPreparing, -1, null);
result.success(null);
} else if (call.method.equals("start")) {
mIjkMediaPlayer.start();
Expand All @@ -263,9 +288,11 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
result.success(null);
} else if (call.method.equals("stop")) {
mIjkMediaPlayer.stop();
handleEvent(PLAYBACK_STATE_CHANGED, stopped, -1, null);
result.success(null);
} else if (call.method.equals("reset")) {
mIjkMediaPlayer.reset();
handleEvent(PLAYBACK_STATE_CHANGED, idle, -1, null);
result.success(null);
} else if (call.method.equals("getCurrentPosition")) {
long pos = mIjkMediaPlayer.getCurrentPosition();
Expand All @@ -277,12 +304,13 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
result.success(null);
} else if (call.method.equals("seekTo")) {
final Integer msec = call.argument("msec");
if (mState == completed)
handleEvent(PLAYBACK_STATE_CHANGED, paused, -1, null);
mIjkMediaPlayer.seekTo(msec != null ? msec.longValue() : 0);
result.success(null);
} else if (call.method.equals("setLoop")) {
final Integer loopCount = call.argument("loop");
// todo update ijkplayer, add set loop count api
mIjkMediaPlayer.setLooping(loopCount != null && loopCount == 0);
mIjkMediaPlayer.setLoopCount(loopCount != null ? loopCount : 1);
result.success(null);
} else if (call.method.equals("setSpeed")) {
final Double speed = call.argument("speed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.view.TextureRegistry;

/**
* FijkPlugin
Expand Down
Loading

0 comments on commit 9f853ec

Please sign in to comment.