Hdmediaplayer
This kind of package relies on Google MediaPlayer two times package.
Google China API Link: https://developer.android.google.cn/guide/topics/media/mediaplayer.html
Directory
- How to import to a project
- How to use
- About Me
- License
How to import to a project
Support Jcenter mode import.
Support local module mode import.
Jcenter Mode Import
- Add the dependencies in the Build.gradle in the module that needs to use this library
{ compile ‘com.yhd.hdmediaplayer:hdmediaplayer:1.0.1‘}
Module Mode Import
- Download the entire project, copy the Hdmediaplayer to the project root directory, and add the Settings.gradle
include‘:hdmediaplayer‘
- Add the dependencies in the Build.gradle in the module that needs to use this library
dependencies { project(‘:hdmediaplayer‘)}
How to use
This class supports the playback of music (. mp3,. wav,. ogg) and video (. mp4,. 3gp) as well as the corresponding format of network streaming media.
If you want to play a video, you need the control: Surfaceview.
- A line of code is implemented to play the MP4 in the assets directory:
MediaPlayerHelper.getInstance().setSurfaceView((SurfaceView)findViewById(R.id.surfaceView)).playAsset(MainActivity.this,"test.mp4");
- A line of code is implemented to play the MP3 in the assets directory:
MediaPlayerHelper.getInstance().playAsset(MainActivity.this,"test.mp3");
- A line of code to play network streaming media or local full-channel runoff media:
/** * urlString 可为网络流媒体连接,也可以为本地存储全路径链接 */MediaPlayerHelper.getInstance().setSurfaceView((SurfaceView)findViewById(R.id.surfaceView)).play(urlString);
- If you want a detailed callback message:
MediaPlayerHelper.getInstance().setMediaPlayerHelperCallBack(new MediaPlayerHelper.MediaPlayerHelperCallBack() { @Override publicvoidonCallBack(MediaPlayerHelper.CallBackState state, MediaPlayerHelper mediaPlayerHelper, Object... args) { Log.v(TAG,"--"+state.toString()); if(state== MediaPlayerHelper.CallBackState.PROGRESS){ int percent=(int)args[0]; Log.v(TAG,"--progress:"+percent); } }});
- For more usage please see demo:
/** 设置播放进度回调时间间隔 */MediaPlayerHelper.getInstance().setProgressInterval(msec);/** 获得MediaPlayer对象,进行更多的自定义的操作 */MediaPlayerHelper.getInstance().getMediaPlayer().pause();MediaPlayerHelper.getInstance().getMediaPlayer().start();MediaPlayerHelper.getInstance().getMediaPlayer().stop();
About Me
欢迎 Star Fork交流地址:尹海德([email protected])
License
Copyright 2017 YinhaideLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
GitHub Portal Https://github.com/yinhaide/HDMediaPlayer
Android uses MediaPlayer to play streaming media, support remote and local streaming, one line of code implementation