Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 152b4759
authored
2025-12-23 18:57:36 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
ios播放测试
1 parent
3eaabf7c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
9 deletions
lib/services/player_service.dart
lib/services/player_service.dart
View file @
152b475
...
...
@@ -2,7 +2,6 @@ import 'dart:async';
import
'dart:io'
;
import
'package:audio_session/audio_session.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter_sound/flutter_sound.dart'
;
class
PlayerService
{
...
...
@@ -31,10 +30,10 @@ class PlayerService {
// 打开播放器
try
{
// 针对iOS, 需要控制不使用听筒进行播放
if
(
Platform
.
isIOS
)
{
var
audioSession
=
await
AudioSession
.
instance
;
await
audioSession
.
configure
(
AudioSessionConfiguration
.
speech
());
}
//
if (Platform.isIOS) {
//
var audioSession = await AudioSession.instance;
//
await audioSession.configure(AudioSessionConfiguration.speech());
//
}
final
player
=
FlutterSoundPlayer
();
_player
=
(
await
player
.
openPlayer
())!;
...
...
@@ -70,6 +69,25 @@ class PlayerService {
}
}
// 针对iOS, 需要控制不使用听筒进行播放
if
(
Platform
.
isIOS
)
{
final
session
=
await
AudioSession
.
instance
;
await
session
.
configure
(
AudioSessionConfiguration
(
avAudioSessionCategory:
AVAudioSessionCategory
.
playback
,
avAudioSessionCategoryOptions:
AVAudioSessionCategoryOptions
.
allowBluetooth
,
avAudioSessionMode:
AVAudioSessionMode
.
spokenAudio
,
avAudioSessionRouteSharingPolicy:
AVAudioSessionRouteSharingPolicy
.
defaultPolicy
,
avAudioSessionSetActiveOptions:
AVAudioSessionSetActiveOptions
.
notifyOthersOnDeactivation
,
androidAudioAttributes:
AndroidAudioAttributes
(
contentType:
AndroidAudioContentType
.
speech
,
flags:
AndroidAudioFlags
.
none
,
usage:
AndroidAudioUsage
.
media
,
),
androidAudioFocusGainType:
AndroidAudioFocusGainType
.
gain
,
androidWillPauseWhenDucked:
true
,
));
}
// // 获取当前音频会话配置
// AudioSession session = await AudioSession.instance;
// if (session.isConfigured) {
...
...
@@ -83,10 +101,10 @@ class PlayerService {
// debugPrint('还未配置音频会话');
// }
if
(
Platform
.
isIOS
)
{
var
currentRoute
=
await
AVAudioSession
().
currentRoute
;
debugPrint
(
'当前音频路由-------------------:
${currentRoute.outputs}
'
);
}
//
if (Platform.isIOS) {
//
var currentRoute = await AVAudioSession().currentRoute;
//
debugPrint('当前音频路由-------------------: ${currentRoute.outputs}');
//
}
_playId
=
playId
;
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment