shogo4405 / HaishinKit.dart

Camera and Microphone streaming library via RTMP for Flutter.
https://pub.dev/packages/haishin_kit
BSD 3-Clause "New" or "Revised" License
32 stars 20 forks source link

StreamViewTexture height and steramview resolution #58

Closed ting28418 closed 5 months ago

ting28418 commented 5 months ago

Describe the bug

Can't adjust StreamViewTexture to show full screen camera.

To Reproduce

If changes like Future _updatePlatformState(BoxConstraints constraints) async { widget.netStream?.updateTextureSize({ "width": constraints.maxWidth, "height": constraints.maxHeight/3, }); show full screen of view but resolution was too bad show object taller and see unclear

Expected behavior

Want to know how to modify to show texture with full screen and high resolution to see user clearly

Version

Flutter 3.19.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision ba39319843 (3 months ago) • 2024-03-07 15:22:21 -0600 Engine • revision 2e4ba9c6fb Tools • Dart 3.3.1 • DevTools 2.31.1

Smartphone info.

Huawei nova 3i

Additional context

No response

Screenshots

No response

Relevant log output

No response

shogo4405 commented 5 months ago

I understand that it didn't work well. However, I didn't understand what the expected result was. You mentioned that it is not high resolution, but what did you look at and how did you determine that?

ting28418 commented 5 months ago

I understand that it didn't work well. However, I didn't understand what the expected result was. You mentioned that it is not high resolution, but what did you look at and how did you determine that?

Sorry for inconvenience, We want to show StreamViewTexture with full screen ,from the example code show StreamViewTexture show at the center of phone manage height but not work how can we do to show full screen

shogo4405 commented 5 months ago

I don't understand the question. I think our definitions of "full screen" might be different. I need you to show the code you wrote and provide details on the results you got.

widget.netStream?.updateTextureSize({ "width": constraints.maxWidth, "height": constraints.maxHeight/3, })

With this code, it seems like constraints.maxHeight / 3 specifies one-third of the screen size, so it appears that the specification is not as intended.

ting28418 commented 5 months ago

``import 'package:flutter/material.dart'; import 'package:haishin_kit/stream.dart';

class StreamViewTexture extends StatefulWidget { const StreamViewTexture(this.netStream, {Key? key}) : super(key: key);

final Stream? netStream;

@override State createState() => _StreamViewTextureState(); }

class _StreamViewTextureState extends State { int? _textureId;

@override void initState() { super.initState(); initPlatformState(); }

Future initPlatformState() async { int? textureId = await widget.netStream?.registerTexture({}); setState(() { _textureId = textureId; }); }

@override Widget build(BuildContext context) { if (_textureId == null) { return Container( color: Colors.black, ); }

return LayoutBuilder(
  builder: (context, constraints) {
    _updatePlatformState(constraints);
    return Texture(textureId: _textureId!);
  },
);

}

Future _updatePlatformState(BoxConstraints constraints) async { widget.netStream?.updateTextureSize({ "width": constraints.maxWidth, "height": constraints.maxHeight, }); } }

Result was attach pic (result1.jpeg) result1

import 'package:flutter/material.dart'; import 'package:haishin_kit/stream.dart';

class StreamViewTexture extends StatefulWidget { const StreamViewTexture(this.netStream, {Key? key}) : super(key: key);

final Stream? netStream;

@override State createState() => _StreamViewTextureState(); }

class _StreamViewTextureState extends State { int? _textureId;

@override void initState() { super.initState(); initPlatformState(); }

Future initPlatformState() async { int? textureId = await widget.netStream?.registerTexture({}); setState(() { _textureId = textureId; }); }

@override Widget build(BuildContext context) { if (_textureId == null) { return Container( color: Colors.black, ); }

return LayoutBuilder(
  builder: (context, constraints) {
    _updatePlatformState(constraints);
    return Texture(textureId: _textureId!);
  },
);

}

Future _updatePlatformState(BoxConstraints constraints) async { widget.netStream?.updateTextureSize({ "width": constraints.maxWidth, "height": constraints.maxHeight/3, }); } } Result2 was attach pic (result2 result2 .jpeg)

body: Center( child: _stream == null ? const Text("") : StreamViewTexture(_stream), ), floatingActionButton: FloatingActionButton( child: _recording ? const Icon(Icons.fiber_smart_record) : const Icon(Icons.not_started), onPressed: ()async { if (_recording) { _connection?.close(); setState(() { _recording = false; }); } else { _connection?.connect("rtmp://example.com/live");

        }
      },
    ),

Here is Videosetting use in

Future initPlatformState() async { await Permission.camera.request(); await Permission.microphone.request();

// Set up AVAudioSession for iOS.
final session = await AudioSession.instance;
await session.configure(const AudioSessionConfiguration(
  avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
  avAudioSessionCategoryOptions:
      AVAudioSessionCategoryOptions.allowBluetooth,
));

RtmpConnection connection = await RtmpConnection.create();

connection.eventChannel.receiveBroadcastStream().listen((event) {
  print("event: $event");
  switch (event["data"]["code"]) {
    case 'NetConnection.Connect.Success':
      if (_mode == "publish") {
        _stream?.publish("8910fe31-d7bb-4f9c-a4d5-af4e3d3c");
      } else {
        _stream?.play("8910fe31-d7bb-4f9c-a4d5-af4e3d3c");
      }
      setState(() {
        _recording = true;
      });
      break;
  }
});

RtmpStream stream = await RtmpStream.create(connection);
stream.audioSettings = AudioSettings(bitrate: 64 * 1000);
stream.videoSettings = VideoSettings(
  width: 1920,
  height: 1080,
  bitrate: 2700 * 1000,
   profileLevel: ProfileLevel.h264HighAutoLevel,
);
stream.attachAudio(AudioSource());
stream.attachVideo(VideoSource(position: currentPosition));

if (!mounted) return;

setState(() {
  _connection = connection;
  _stream = stream;
});

}

How to show streamviewtexture full screen of phone and clear resolution

shogo4405 commented 5 months ago

Thank you for your message. I couldn't understand the content of your question. I don't think we can make any progress if we continue like this, so I will stop handling this matter.