يتطلب إنشاء مكتبة مثل هذا قدرًا كبيرًا من الوقت والجهد.
إذا كنت ترغب في إظهار تقديرك ، فيمكنك القيام بذلك أدناه:
شاشة خفيفة الوزن وتسجيل الصوت مكتبة Android
يتطلب مستوى API 21>
قم بتنزيل التطبيق التجريبي هنا
أضف ما يلي في جذر build.gradle في نهاية المستودعات:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
تنفيذ المكتبة في مستوى التطبيق الخاص بك build.gradle:
dependencies {
implementation 'com.github.HBiSoft:HBRecorder:3.0.7'
}
Activity
، قم أولاً بتنفيذ HBRecorder
، كما هو موضح أدناه: public class MainActivity extends AppCompatActivity implements HBRecorderListener {
Alt+Enter
لتنفيذ الطرق التالية: @ Override
public void HBRecorderOnStart () {
//When the recording starts
}
@ Override
public void HBRecorderOnComplete () {
//After file was created
}
@ Override
public void HBRecorderOnError ( int errorCode ) {
//When an error occurs
}
@ Override
public void HBRecorderOnPause () {
//When recording was paused
}
@ Override
public void HBRecorderOnResume () {
//When recording was resumed
}
HBRecorder
كما هو موضح أدناه: public class MainActivity extends AppCompatActivity implements HBRecorderListener {
HBRecorder hbRecorder ;
@ Override
protected void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( R . layout . activity_main );
//Init HBRecorder
hbRecorder = new HBRecorder ( this , this );
}
< uses - permission android : name = "android.permission.WRITE_EXTERNAL_STORAGE" />
< uses - permission android : name = "android.permission.WRITE_INTERNAL_STORAGE" />
< uses - permission android : name = "android.permission.RECORD_AUDIO" />
< uses - permission android : name = "android.permission.FOREGROUND_SERVICE" />
<!-- For SDK 34 -->
< uses - permission android : name = "android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
هذا كل شيء ، HBRecorder
جاهز الآن لاستخدامه.
private void startRecordingScreen () {
MediaProjectionManager mediaProjectionManager = ( MediaProjectionManager ) getSystemService ( Context . MEDIA_PROJECTION_SERVICE );
Intent permissionIntent = mediaProjectionManager != null ? mediaProjectionManager . createScreenCaptureIntent () : null ;
startActivityForResult ( permissionIntent , SCREEN_RECORD_REQUEST_CODE );
}
@ Override
protected void onActivityResult ( int requestCode , int resultCode , Intent data ) {
super . onActivityResult ( requestCode , resultCode , data );
if ( requestCode == SCREEN_RECORD_REQUEST_CODE ) {
if ( resultCode == RESULT_OK ) {
//Start screen recording
hbRecorder . startScreenRecording ( data , resultCode );
}
}
}
// Set the output path as a String
// Only use this on devices running Android 9 and lower or you have to add android:requestLegacyExternalStorage="true" in your manifest
// Defaults to - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
hbrecorder . setOutputPath ( String );
// Set output Uri
// Only use this on devices running Android 10>
// When setting a Uri ensure you pass the same name to HBRecorder as what you set in ContentValues (DISPLAY_NAME and TITLE)
hbRecorder . setOutputUri ( Uri );
// Set file name as String
// Defaults to - quality + time stamp. For example HD-2019-08-14-10-09-58.mp4
hbrecorder . setFileName ( String );
// Set audio bitrate as int
// Defaults to - 128000
hbrecorder . setAudioBitrate ( int );
// Set audio sample rate as int
// Defaults to - 44100
hbrecorder . setAudioSamplingRate ( int );
// Enable/Disable audio
// Defaults to true
hbrecorder . isAudioEnabled ( boolean );
// Enable/Disable HD Video
// Defaults to true
hbrecorder . recordHDVideo ( boolean );
// Get file path as String
hbrecorder . getFilePath ();
// Get file name as String
hbrecorder . getFileName ();
// Start recording screen by passing it as Intent inside onActivityResult
hbrecorder . startScreenRecording ( Intent );
// Pause screen recording (only available for devices running 24>)
hbrecorder . pauseScreenRecording ();
// Resume screen recording
hbreccorder . resumeScreenRecording ();
// Stop screen recording
hbrecorder . stopScreenRecording ();
// Check if recording is in progress
hbrecorder . isBusyRecording ();
// Set notification icon by passing, for example R.drawable.myicon
// Defaults to R.drawable.icon
hbrecorder . setNotificationSmallIcon ( int );
// Set notification icon using byte array
hbrecorder . setNotificationSmallIcon ( byte []);
// Set notification icon using vector drawable
hbRecorder . setNotificationSmallIconVector ( vector );
// Set notification title
// Defaults to "Recording your screen"
hbrecorder . setNotificationTitle ( String );
// Set notification description
// Defaults to "Drag down to stop the recording"
hbrecorder . setNotificationDescription ( String );
// Set notification stop button text
// Defaults to "STOP RECORDING"
hbrecorder . setNotificationButtonText ( String );
// Set output orientation (in degrees)
hbrecorder . setOrientationHint ( int );
// Set max output file size
hbrecorder . setMaxFileSize ( long );
// Set max time (in seconds)
hbRecorder . setMaxDuration ( int );
عندما تريد تمكين إعدادات مخصصة ، يجب عليك الاتصال أولاً:
hbRecorder . enableCustomSettings ();
ثم يمكنك تعيين ما يلي:
//MUST BE ONE OF THE FOLLOWING - https://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html
hbRecorder . setAudioSource ( String );
//MUST BE ONE OF THE FOLLOWING - https://developer.android.com/reference/android/media/MediaRecorder.VideoEncoder.html
hbRecorder . setVideoEncoder ( String );
//If nothing is provided, it will select the highest value supported by your device
hbRecorder . setScreenDimensions ( HeightInPx , WidthInPx );
//Frame rate is device dependent
//You can use Camcoderprofile to determine the frame rate
hbRecorder . setVideoFrameRate ( int );
//The bitrate is also dependent on the device and the frame rate that is set
hbRecorder . setVideoBitrate ( int );
//MUST BE ONE OF THE FOLLOWING - https://developer.android.com/reference/android/media/MediaRecorder.OutputFormat.html
hbRecorder . setOutputFormat ( String );
من المهم ملاحظة أن القيود تعتمد على الجهاز. من الأفضل تعيين مشفر الفيديو على "افتراضي" والسماح لـ MediaRecorder
باختيار أفضل تشفير.
في التطبيق التجريبي ، سيكون لديك خيار اختبار مشفرات الفيديو المختلفة ، وتنسيقات معدل البت ، ومعدل الإطار وتنسيقات الإخراج. إذا كان جهازك لا يدعم أيًا من المعلمات التي حددتها ، فسيتم استدعاء HBRecorderOnError
.