Skip to content

Commit 9f853ec

Browse files
committed
Merge branch 'release-0.1.0'
2 parents 8729fde + 05346b3 commit 9f853ec

37 files changed

+1437
-457
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
## next
22
--------------------------------
33

4+
## 0.1.0
5+
- update ijkplauer to f0.3.5
6+
- fijkplayer err state and FijkException
7+
- support playing flutter asset file
8+
- unit test and widget test
9+
- pass fijkoption arguments and set player's option
10+
411
## 0.0.9
512
--------------------------------
613
- update ijkplayer to f0.3.4

README.en.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# fijkplayer (Video player plugin for Flutter)
22

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

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

1112

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

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

2020
```yaml
2121
dependencies:
22-
fijkplayer: ^0.0.6
22+
fijkplayer: ^0.1.0
2323
```
2424
2525

README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# fijkplayer (Video player plugin for Flutter)
2+
3+
4+
[![pub package](https://img.shields.io/pub/v/fijkplayer.svg)](https://pub.dartlang.org/packages/fijkplayer)    
5+
[![Build Status](https://travis-ci.org/befovy/fijkplayer.svg?branch=master)](https://travis-ci.org/befovy/fijkplayer)    
6+
7+
A Flutter media player plugin for iOS and android based on [ijkplayer](https://github.com/befovy/ijkplayer)
8+
9+
10+
*Read this in other languages: [English](README.en.md), [简体中文](README.zh-cn.md).*
11+
12+
13+
[Feedback welcome](https://github.com/befovy/fijkplayer/issues) and
14+
[Pull Requests](https://github.com/befovy/fijkplayer/pulls) are most welcome!
15+
16+
## Installation
17+
18+
Add `fijkplayer` as a [dependency in your pubspec.yaml file](https://flutter.io/using-packages/).
19+
20+
```yaml
21+
dependencies:
22+
fijkplayer: ^0.1.0
23+
```
24+
25+
26+
## Example
27+
28+
```dart
29+
import 'package:fijkplayer/fijkplayer.dart';
30+
import 'package:flutter/material.dart';
31+
32+
class VideoScreen extends StatefulWidget {
33+
final String url;
34+
35+
VideoScreen({@required this.url});
36+
37+
@override
38+
_VideoScreenState createState() => _VideoScreenState();
39+
}
40+
41+
class _VideoScreenState extends State<VideoScreen> {
42+
final FijkPlayer player = FijkPlayer();
43+
44+
_VideoScreenState();
45+
46+
@override
47+
void initState() {
48+
super.initState();
49+
player.setDataSource(widget.url, autoPlay: true);
50+
}
51+
52+
@override
53+
Widget build(BuildContext context) {
54+
return Scaffold(
55+
appBar: AppBar(title: Text("Fijkplayer Example")),
56+
body: Container(
57+
alignment: Alignment.center,
58+
child: FijkView(
59+
player: player,
60+
),
61+
));
62+
}
63+
64+
@override
65+
void dispose() {
66+
super.dispose();
67+
player.release();
68+
}
69+
}
70+
71+
```
72+
73+
## Demo Screenshots
74+
75+
iOS screenshots
76+
<div>
77+
<img src="https://user-images.githubusercontent.com/51129600/61178868-abefcc00-a629-11e9-851f-f4b2ab0028fb.jpeg" height="300px" alt="ios_input" >
78+
&nbsp; &nbsp; &nbsp;
79+
<img src="https://user-images.githubusercontent.com/51129600/61178869-abefcc00-a629-11e9-8b15-872d8cd207b9.jpeg" height="300px" alt="ios_video" >
80+
</div>
81+
82+
android screenshots
83+
84+
<div>
85+
<img src="https://user-images.githubusercontent.com/51129600/61178866-ab573580-a629-11e9-8019-77a400998531.jpeg" height="300px" alt="android_home" >
86+
&nbsp; &nbsp; &nbsp;
87+
<img src="https://user-images.githubusercontent.com/51129600/61178867-ab573580-a629-11e9-8829-8a37efb39d7d.jpeg" height="300px" alt="android_video" >
88+
</div>
89+
90+
91+
92+
## iOS Warning
93+
94+
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).
95+

README.zh-cn.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
```yaml
2424
dependencies:
25-
fijkplayer: ^0.0.9
25+
fijkplayer: ^0.1.0
2626
```
2727
2828
## 基础用法
@@ -111,8 +111,7 @@ pod 'FIJKPlayer'
111111
```gradle
112112
dependencies {
113113
// fijkplayer-full include the java lib and native shared libs for armv5 armv7 arm64 x86 x86_64
114-
implementation 'com.befovy.fijkplayer:fijkplayer-full:0.3.4'
115-
implementation 'com.befovy.fijkplayer:fijkplayer-full:0.3.4'
114+
implementation 'com.befovy.fijkplayer:fijkplayer-full:0.3.5'
116115
}
117116
```
118117

android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
.DS_Store
77
/build
88
/captures
9+
/aars

android/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ android {
3232
lintOptions {
3333
disable 'InvalidPackage'
3434
}
35+
36+
aaptOptions {
37+
noCompress '.flv', '.mp4'
38+
}
39+
3540
}
3641

3742

3843
dependencies {
3944

4045
// implementation(name: 'fijkplayer-full-release', ext: 'aar')
46+
4147
// fijkplayer-full include the java lib and native shared libs for armv5 armv7 arm64 x86 x86_64
42-
implementation 'com.befovy.fijkplayer:fijkplayer-full:0.3.4'
48+
implementation 'com.befovy.fijkplayer:fijkplayer-full:0.3.5'
4349
implementation 'com.android.support:support-annotations:28.0.0'
4450
}

android/src/main/java/com/befovy/fijkplayer/FijkPlayer.java

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.befovy.fijkplayer;
22

33
import android.content.Context;
4-
import android.content.res.AssetFileDescriptor;
54
import android.content.res.AssetManager;
65
import android.graphics.SurfaceTexture;
76
import android.net.Uri;
@@ -12,7 +11,9 @@
1211
import androidx.annotation.NonNull;
1312

1413
import java.io.File;
14+
import java.io.FileNotFoundException;
1515
import java.io.IOException;
16+
import java.io.InputStream;
1617
import java.util.HashMap;
1718
import java.util.Map;
1819
import java.util.concurrent.atomic.AtomicInteger;
@@ -30,7 +31,22 @@ public class FijkPlayer implements MethodChannel.MethodCallHandler, IjkEventList
3031

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

34+
final private static int idle = 0;
35+
final private static int initialized = 1;
36+
final private static int asyncPreparing = 2;
37+
@SuppressWarnings("unused")
38+
final private static int prepared = 3;
39+
@SuppressWarnings("unused")
40+
final private static int started = 4;
41+
final private static int paused = 5;
42+
final private static int completed = 6;
43+
final private static int stopped = 7;
44+
@SuppressWarnings("unused")
45+
final private static int error = 8;
46+
final private static int end = 9;
47+
3348
final private int mPlayerId;
49+
private int mState;
3450
final private IjkMediaPlayer mIjkMediaPlayer;
3551
final private Context mContext;
3652

@@ -53,6 +69,7 @@ public class FijkPlayer implements MethodChannel.MethodCallHandler, IjkEventList
5369
FijkPlayer(PluginRegistry.Registrar registrar) {
5470
mRegistrar = registrar;
5571
mPlayerId = atomicId.incrementAndGet();
72+
mState = 0;
5673
mIjkMediaPlayer = new IjkMediaPlayer();
5774
mIjkMediaPlayer.addIjkEventListener(this);
5875

@@ -93,9 +110,8 @@ long setupSurface() {
93110
}
94111

95112
void release() {
96-
mIjkMediaPlayer.stop();
113+
handleEvent(PLAYBACK_STATE_CHANGED, end, mState, null);
97114
mIjkMediaPlayer.release();
98-
99115
if (mSurfaceTextureEntry != null) {
100116
mSurfaceTextureEntry.release();
101117
mSurfaceTextureEntry = null;
@@ -121,6 +137,7 @@ private void handleEvent(int what, int arg1, int arg2, Object extra) {
121137
mEventSink.success(event);
122138
break;
123139
case PLAYBACK_STATE_CHANGED:
140+
mState = arg1;
124141
event.put("event", "state_change");
125142
event.put("new", arg1);
126143
event.put("old", arg2);
@@ -151,6 +168,9 @@ private void handleEvent(int what, int arg1, int arg2, Object extra) {
151168
event.put("height", arg2);
152169
mEventSink.success(event);
153170
break;
171+
case ERROR:
172+
mEventSink.error(String.valueOf(arg1), extra.toString(), arg2);
173+
break;
154174
default:
155175
// Log.d("FLUTTER", "jonEvent:" + what);
156176
break;
@@ -166,6 +186,7 @@ public void onEvent(IjkMediaPlayer ijkMediaPlayer, int what, int arg1, int arg2,
166186
case BUFFERING_END:
167187
case BUFFERING_UPDATE:
168188
case VIDEO_SIZE_CHANGED:
189+
case ERROR:
169190
handleEvent(what, arg1, arg2, extra);
170191
break;
171192
default:
@@ -200,6 +221,7 @@ private void applyOptions(Object options) {
200221

201222
@Override
202223
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
224+
//noinspection IfCanBeSwitch
203225
if (call.method.equals("setupSurface")) {
204226
long viewId = setupSurface();
205227
result.success(viewId);
@@ -223,7 +245,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
223245
String url = call.argument("url");
224246
Uri uri = Uri.parse(url);
225247
boolean openAsset = false;
226-
if ("assets".equals(uri.getScheme())) {
248+
if ("asset".equals(uri.getScheme())) {
227249
openAsset = true;
228250
String host = uri.getHost();
229251
String path = uri.getPath() != null ? uri.getPath().substring(1) : "";
@@ -237,9 +259,8 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
237259
try {
238260
if (openAsset) {
239261
AssetManager assetManager = mRegistrar.context().getAssets();
240-
AssetFileDescriptor fd = assetManager.openFd(uri.getPath() != null ? uri.getPath() : "");
241-
//mIjkMediaPlayer.setDataSource(fd.getFileDescriptor());
242-
mIjkMediaPlayer.setDataSource(new RawMediaDataSource(fd, mRegistrar.context(), uri.getPath()));
262+
InputStream is = assetManager.open(uri.getPath() != null ? uri.getPath() : "", AssetManager.ACCESS_RANDOM);
263+
mIjkMediaPlayer.setDataSource(new RawMediaDataSource(is));
243264
} else {
244265
if (TextUtils.isEmpty(uri.getScheme()) || "file".equals(uri.getScheme())) {
245266
IMediaDataSource dataSource = new FileMediaDataSource(new File(uri.toString()));
@@ -248,12 +269,16 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
248269
mIjkMediaPlayer.setDataSource(mContext, uri);
249270
}
250271
}
272+
handleEvent(PLAYBACK_STATE_CHANGED, initialized, -1, null);
251273
result.success(null);
274+
} catch (FileNotFoundException e) {
275+
result.error("-875574348", "Local File not found:" + e.getMessage(), null);
252276
} catch (IOException e) {
253-
result.error(e.getMessage(), null, null);
277+
result.error("-1162824012", "Local IOException:" + e.getMessage(), null);
254278
}
255279
} else if (call.method.equals("prepareAsync")) {
256280
mIjkMediaPlayer.prepareAsync();
281+
handleEvent(PLAYBACK_STATE_CHANGED, asyncPreparing, -1, null);
257282
result.success(null);
258283
} else if (call.method.equals("start")) {
259284
mIjkMediaPlayer.start();
@@ -263,9 +288,11 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
263288
result.success(null);
264289
} else if (call.method.equals("stop")) {
265290
mIjkMediaPlayer.stop();
291+
handleEvent(PLAYBACK_STATE_CHANGED, stopped, -1, null);
266292
result.success(null);
267293
} else if (call.method.equals("reset")) {
268294
mIjkMediaPlayer.reset();
295+
handleEvent(PLAYBACK_STATE_CHANGED, idle, -1, null);
269296
result.success(null);
270297
} else if (call.method.equals("getCurrentPosition")) {
271298
long pos = mIjkMediaPlayer.getCurrentPosition();
@@ -277,12 +304,13 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
277304
result.success(null);
278305
} else if (call.method.equals("seekTo")) {
279306
final Integer msec = call.argument("msec");
307+
if (mState == completed)
308+
handleEvent(PLAYBACK_STATE_CHANGED, paused, -1, null);
280309
mIjkMediaPlayer.seekTo(msec != null ? msec.longValue() : 0);
281310
result.success(null);
282311
} else if (call.method.equals("setLoop")) {
283312
final Integer loopCount = call.argument("loop");
284-
// todo update ijkplayer, add set loop count api
285-
mIjkMediaPlayer.setLooping(loopCount != null && loopCount == 0);
313+
mIjkMediaPlayer.setLoopCount(loopCount != null ? loopCount : 1);
286314
result.success(null);
287315
} else if (call.method.equals("setSpeed")) {
288316
final Double speed = call.argument("speed");

android/src/main/java/com/befovy/fijkplayer/FijkPlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
1212
import io.flutter.plugin.common.MethodChannel.Result;
1313
import io.flutter.plugin.common.PluginRegistry.Registrar;
14-
import io.flutter.view.TextureRegistry;
1514

1615
/**
1716
* FijkPlugin

0 commit comments

Comments
 (0)