Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hosting view in view hierarchy for platform view: 0 [BUG] #112

Closed
mohamedELamine opened this issue Dec 6, 2022 · 3 comments
Closed

Hosting view in view hierarchy for platform view: 0 [BUG] #112

mohamedELamine opened this issue Dec 6, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@mohamedELamine
Copy link

when I use agora Uikit, I found this Error
E/FrameEvents(21365): updateAcquireFence: Did not find frame.
this is code:
import 'package:agora_uikit/agora_uikit.dart';
import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatefulWidget {
const MyApp({super.key});

@OverRide
State createState() => _MyAppState();
}

class _MyAppState extends State {
final AgoraClient client = AgoraClient(
agoraConnectionData: AgoraConnectionData(
appId: "My appId",
channelName: "test",
username: "user",
),
enabledPermission: [Permission.camera, Permission.microphone],
agoraChannelData: AgoraChannelData(
channelProfileType: ChannelProfileType.channelProfileLiveBroadcasting,
clientRoleType: ClientRoleType.clientRoleBroadcaster,
),
);

@OverRide
void initState() {
super.initState();
initAgora();
}

void initAgora() async {
await client.initialize();
}

@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Agora VideoUIKit'),
centerTitle: true,
),
body: SafeArea(
child: Stack(
children: [
AgoraVideoViewer(
client: client,
layoutType: Layout.floating,
floatingLayoutContainerHeight: 100,
floatingLayoutContainerWidth: 100,
showNumberOfUsers: true,
showAVState: true,
enableHostControls: true, // Add this to enable host controls
),
AgoraVideoButtons(
client: client,
enabledButtons: [
BuiltInButtons.toggleMic,
BuiltInButtons.callEnd,
BuiltInButtons.switchCamera
],
)
],
),
),
),
);
}
}

@mohamedELamine mohamedELamine added the bug Something isn't working label Dec 6, 2022
@Meherdeep
Copy link
Contributor

This error should not cause any problem in the running of the UIKit. Is there something that is not working for you properly?

@mohamedELamine
Copy link
Author

when i click join
image
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

import 'package:agora_rtc_engine/agora_rtc_engine.dart';
import 'package:flutter/material.dart';

const String appId = "756d0451e027460dbb9212a2f46c141a";
void main() {
runApp(const MyApp());
}

class MyApp extends StatefulWidget {
const MyApp({super.key});

@OverRide
State createState() => _MyAppState();
}

class _MyAppState extends State {
late RtcEngine agoraEngine; // Agora engine instance
String channelName = "ARyhan";
final GlobalKey scaffoldMessengerKey =
GlobalKey(); // Global key to access the scaffold

String token = "9088f484799548efba2ac5f987c63df9";
int uid = 0; // uid of the local user

bool _isHost =
true; // Indicates whether the user has joined as a host or audience

bool _isJoined = false; // Indicates if the local user has joined the channel
int? _remoteUid; // uid of the remote user

@OverRide
void dispose() async {
await agoraEngine.leaveChannel();
super.dispose();
}

@OverRide
void initState() {
super.initState();
setupVideoSDKEngine();
}

showMessage(String message) {
scaffoldMessengerKey.currentState?.showSnackBar(SnackBar(
content: Text(message),
));
}

Future setupVideoSDKEngine() async {
// retrieve or request camera and microphone permissions
await [Permission.microphone, Permission.camera].request();

//create an instance of the Agora engine
agoraEngine = createAgoraRtcEngine();
await agoraEngine.initialize(const RtcEngineContext(appId: appId));

await agoraEngine.enableVideo();

// Register the event handler
agoraEngine.registerEventHandler(
  RtcEngineEventHandler(
    onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
      showMessage(
          "Local user uid:${connection.localUid} joined the channel");
      setState(() {
        _isJoined = true;
      });
    },
    onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
      showMessage("Remote user uid:$remoteUid joined the channel");
      setState(() {
        _remoteUid = remoteUid;
      });
    },
    onUserOffline: (RtcConnection connection, int remoteUid,
        UserOfflineReasonType reason) {
      showMessage("Remote user uid:$remoteUid left the channel");
      setState(() {
        _remoteUid = null;
      });
    },
  ),
);

}

void join() async {
// Set channel options
ChannelMediaOptions options;

// Set channel profile and client role
if (_isHost) {
  options = const ChannelMediaOptions(
    clientRoleType: ClientRoleType.clientRoleBroadcaster,
    channelProfile: ChannelProfileType.channelProfileLiveBroadcasting,
  );
  await agoraEngine.startPreview();
} else {
  options = const ChannelMediaOptions(
    clientRoleType: ClientRoleType.clientRoleAudience,
    channelProfile: ChannelProfileType.channelProfileLiveBroadcasting,
  );
}

await agoraEngine.joinChannel(
  token: token,
  channelId: channelName,
  options: options,
  uid: uid,
);

}

void leave() {
setState(() {
_isJoined = false;
_remoteUid = null;
});
agoraEngine.leaveChannel();
}

Widget _videoPanel() {
if (!_isJoined) {
return const Text(
'Join a channel',
textAlign: TextAlign.center,
);
} else if (_isHost) {
// Local user joined as a host
return AgoraVideoView(
controller: VideoViewController(
rtcEngine: agoraEngine,
canvas: VideoCanvas(uid: uid),
),
);
} else {
// Local user joined as audience
if (_remoteUid != null) {
return AgoraVideoView(
controller: VideoViewController.remote(
rtcEngine: agoraEngine,
canvas: VideoCanvas(uid: _remoteUid),
connection: RtcConnection(channelId: channelName),
),
);
} else {
return const Text(
'Waiting for a host to join',
textAlign: TextAlign.center,
);
}
}
}

// Set the client role when a radio button is selected
void _handleRadioValueChange(bool? value) async {
setState(() {
_isHost = (value == true);
});
if (_isJoined) leave();
}

@OverRide
Widget build(BuildContext context) {
return MaterialApp(
scaffoldMessengerKey: scaffoldMessengerKey,
home: Scaffold(
appBar: AppBar(
title: const Text('Get started with Interactive Live Streaming'),
),
body: ListView(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
children: [
// Container for the local video
Container(
height: 240,
decoration: BoxDecoration(border: Border.all()),
child: Center(child: _videoPanel()),
),
// Radio Buttons
Row(children: [
Radio(
value: true,
groupValue: _isHost,
onChanged: (value) => _handleRadioValueChange(value),
),
const Text('Host'),
Radio(
value: false,
groupValue: _isHost,
onChanged: (value) => _handleRadioValueChange(value),
),
const Text('Audience'),
]),
// Button Row
Row(
children: [
Expanded(
child: ElevatedButton(
child: const Text("Join"),
onPressed: () => {join()},
),
),
const SizedBox(width: 10),
Expanded(
child: ElevatedButton(
child: const Text("Leave"),
onPressed: () => {leave()},
),
),
],
),
// Button Row ends
],
)),
);
}
}

@Meherdeep
Copy link
Contributor

@mohamedELamine Looks like you're using the agora_rtc_engine package and not the UIKit. For any issue with the core SDK please submit an issue here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants