当前位置: 首页 > news >正文

3 建设营销型网站流程图网站两侧广告代码

3 建设营销型网站流程图,网站两侧广告代码,wordpress新建全屏页面,培训教育flutter开发实战-just_audio实现播放音频暂停音频设置音量等 最近开发过程中遇到需要播放背景音等音频播放#xff0c;这里使用just_audio来实现播放音频暂停音频设置音量等 一、引入just_audio 在pubspec.yaml引入just_audio just_audio: ^2.7.0在iOS上#xff0c;video_p…flutter开发实战-just_audio实现播放音频暂停音频设置音量等 最近开发过程中遇到需要播放背景音等音频播放这里使用just_audio来实现播放音频暂停音频设置音量等 一、引入just_audio 在pubspec.yaml引入just_audio just_audio: ^2.7.0在iOS上video_player使用的是AVPlayer进行播放。 在Android上video_player使用的是ExoPlayer。 二、使用前设置 2.1 在iOS中的设置 在iOS工程中info.plist添加一下设置以便支持HttpsHTTP的视频地址 keyNSAppTransportSecurity/key dictkeyNSAllowsArbitraryLoads/keytrue/ /dict2.2 在Android中的设置 需要在/android/app/src/main/AndroidManifest.xml文件中添加网络权限 uses-permission android:nameandroid.permission.INTERNET/三、just_audio实现播放音频暂停音频设置音量等 引入just_audio后可以使用AudioPlayer来播放音频 3.1 常用操作如下 播放 await _audioPlayer.play();暂停 await _audioPlayer.pause();seek await _audioPlayer.seek(position);停止 await _audioPlayer.pause(); await _audioPlayer.seek(Duration.zero);设置音量 await _audioPlayer.setVolume(volume);3.2 使用just_audio实现播放player 这里通过player来获取SDAudioPlayerState状态控制音频的暂停音频设置音量等操作 import package:flutter_app/manager/logger_manager.dart; import package:just_audio/just_audio.dart;// 播放回调 typedef SDAudioPlayerCallBack void Function(SDAudioPlayerState state, SDAudioPlayerError? error);// 播放音频的状态 enum SDAudioPlayerState {idle, // 默认loading, // 加载中buffering, // 缓存中ready, // 可播放completed, // 播放完成 }// 播放音频出现错误 class SDAudioPlayerError {String? message; }// 定义优先级的类 class SDMusicConfig {// 音频文件地址late String audioUrl ;late bool runLoop false; // 是否循环播放// 构造函数SDMusicConfig(this.audioUrl, this.audioPriority, this.runLoop); }// 播放音频文件 class SDMusicPlayer {// 音频播放late AudioPlayer _audioPlayer;// 优先级late SDMusicConfig _musicConfig;late bool _playing false; // 是否正在播放late SDAudioPlayerState _playerState SDAudioPlayerState.idle; // 状态late SDAudioPlayerCallBack? _playerCallBack;SDMusicPlayer(this._audioPlayer, this._musicConfig){setAudioUrl(this._musicConfig.audioUrl);openPlayCallBack((state, error) {});}SDMusicConfig getMusicConfig() {return _musicConfig;}void openPlayCallBack(SDAudioPlayerCallBack playerCallBack) {_playerCallBack playerCallBack;_audioPlayer.playerStateStream.listen((state) {_playing state.playing;switch(state.processingState) {case ProcessingState.idle: {_playerState SDAudioPlayerState.idle;break;}case ProcessingState.loading: {_playerState SDAudioPlayerState.loading;break;}case ProcessingState.buffering: {_playerState SDAudioPlayerState.buffering;break;}case ProcessingState.ready: {_playerState SDAudioPlayerState.ready;break;}case ProcessingState.completed: {_playerState SDAudioPlayerState.completed;if (_musicConfig.runLoop true) {// 循环播放的时候seek(Duration.zero);play();} else {stop();}break;}default:}if (_playerCallBack ! null) {_playerCallBack!(_playerState, null);}});}// var duration await player.setUrl(https://foo.com/bar.mp3);Futurevoid setAudioUrl(String url) async {SDAudioPlayerError? error;if (url.isNotEmpty) {// Set the audio source but manually load audio at a later point.try {_audioPlayer.setUrl(url, preload: true);// Acquire platform decoders and start loading audio.var duration await _audioPlayer.load();print(url${url} duration${duration});} on PlayerException catch (e) {// iOS/macOS: maps to NSError.code// Android: maps to ExoPlayerException.type// Web: maps to MediaError.code// Linux/Windows: maps to PlayerErrorCode.indexprint(SDAudioPlayer Error code: ${e.code});// iOS/macOS: maps to NSError.localizedDescription// Android: maps to ExoPlaybackException.getMessage()// Web/Linux: a generic message// Windows: MediaPlayerError.messageprint(SDAudioPlayer Error message: ${e.message});error SDAudioPlayerError();error.message e.message;} on PlayerInterruptedException catch (e) {// This call was interrupted since another audio source was loaded or the// player was stopped or disposed before this audio source could complete// loading.LoggerManager().debug(SDAudioPlayer Connection aborted: ${e.message});error SDAudioPlayerError();error.message e.message;} catch (e) {// Fallback for all errorsprint(e: ${e});error SDAudioPlayerError();error.message e.toString();}} else {error SDAudioPlayerError();error.message 播放地址不能为空;}if (_playerCallBack ! null) {_playerCallBack!(_playerState, error);}}void play() async {// Usually you dont want to wait for playback to finish.if (_musicConfig.audioUrl ! null _musicConfig.audioUrl.isNotEmpty) {if (_playing false) {// 正在播放await _audioPlayer.play();}}}void pause() async {if (_musicConfig.audioUrl ! null _musicConfig.audioUrl.isNotEmpty) {await _audioPlayer.pause();}}void stop() async {if (_musicConfig.audioUrl ! null _musicConfig.audioUrl.isNotEmpty) {await _audioPlayer.pause();await _audioPlayer.seek(Duration.zero);}}void seek(Duration position) async {if (_musicConfig.audioUrl ! null _musicConfig.audioUrl.isNotEmpty) {await _audioPlayer.seek(position);}}void setVolume(double volume) async {if (_musicConfig.audioUrl ! null _musicConfig.audioUrl.isNotEmpty) {await _audioPlayer.setVolume(volume);}}// 不需要该播放器则需要调用该方法void dispose() async {await _audioPlayer.dispose();} }四、小结 flutter开发实战-just_audio实现播放音频暂停音频设置音量等。 学习记录每天不停进步。
http://www.pierceye.com/news/757160/

相关文章:

  • 做网站用什么语言比较简单网站seo优化总结
  • 四川省工程建设信息网站南京好的网站设计公司
  • 城市建设单招网站合肥哪个公司做网站好
  • 深圳建站模板建站建筑公司对企业未来希望
  • 商丘网站制作电话文库网站建设
  • 新闻发布网站模板医院网站建设原理
  • 网站开发立项报告网页制作视频教程优质课
  • 网站运营分析竞争对手整站采集wordpress
  • 创建一个网站所需的成本厦门礼品网站商城制作案例
  • 南昌建设企业网站公司游戏源码
  • 网站当电话线做php网站教程视频教程
  • 百度里面的站长工具怎么取消怎么注册公司官网
  • 网站开发遵循软件管理工程师
  • 网站开发问题论文武进网站建设机构
  • 网站建设有哪些种类网站开发工程师岗位
  • 电大形考任在哪个网站做旺道seo优化软件怎么用
  • 新网 网站备案好的作文网站
  • 网站建设技术外包深圳建设公司网站
  • 做旅游网站的数据怎么来垦利网站设计
  • 附近那里有做网站的微信公众平台注册官网
  • 雏鸟短视频app软件下载网站网站建设心得体会500字
  • 权威发布型舆情回应大连网站优化多少钱
  • 怎么做网站步骤免费的怎么用虚拟主机做网站步骤
  • 网站建设精品课程南昌企业网站建设哪家好
  • 网站空间不够用怎么办电子商务公司名字
  • 策划方案网站wordpress设置视频图片
  • 餐饮设计网站有哪些做副业的网站
  • 如何建设一个电子商务网站四川网站建设电话
  • 网站制作学习学网站开发顺序
  • 外语网站建设怎么知道网站的ftp