or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

audio-control.mdcore-playback.mddata-structures.mddiscovery-renderers.mdevent-system.mdindex.mdlow-level-functions.mdmedia-lists.mdvideo-control.md

low-level-functions.mddocs/

0

# Low-Level LibVLC Functions

1

2

Direct access to all LibVLC C API functions for advanced use cases and maximum control. These functions provide the raw LibVLC interface that the high-level wrapper classes are built upon.

3

4

## Capabilities

5

6

### Core LibVLC Functions

7

8

Fundamental LibVLC instance and lifecycle management functions.

9

10

```python { .api }

11

def libvlc_new(argc, argv):

12

"""Create a LibVLC instance.

13

14

Args:

15

argc (int): Number of command line arguments

16

argv (list): List of command line argument strings

17

18

Returns:

19

ctypes.c_void_p: LibVLC instance pointer

20

"""

21

...

22

23

def libvlc_release(instance):

24

"""Decrement the reference count of a libvlc instance.

25

26

Args:

27

instance (ctypes.c_void_p): LibVLC instance pointer

28

"""

29

...

30

31

def libvlc_retain(instance):

32

"""Increment the reference count of a libvlc instance.

33

34

Args:

35

instance (ctypes.c_void_p): LibVLC instance pointer

36

"""

37

...

38

39

def libvlc_get_version():

40

"""Get LibVLC version.

41

42

Returns:

43

str: Version string

44

"""

45

...

46

47

def libvlc_get_compiler():

48

"""Get LibVLC compiler version.

49

50

Returns:

51

str: Compiler version string

52

"""

53

...

54

55

def libvlc_get_changeset():

56

"""Get LibVLC changeset.

57

58

Returns:

59

str: Changeset string

60

"""

61

...

62

63

def libvlc_free(ptr):

64

"""Free memory allocated by LibVLC.

65

66

Args:

67

ptr (ctypes.c_void_p): Pointer to free

68

"""

69

...

70

71

def libvlc_event_attach(event_manager, event_type, callback, user_data):

72

"""Register for an event notification.

73

74

Args:

75

event_manager (ctypes.c_void_p): Event manager

76

event_type (int): Event type to listen for

77

callback (function): Callback function

78

user_data (ctypes.c_void_p): User data for callback

79

80

Returns:

81

int: 0 on success, ENOMEM on error

82

"""

83

...

84

85

def libvlc_event_detach(event_manager, event_type, callback, user_data):

86

"""Unregister an event notification.

87

88

Args:

89

event_manager (ctypes.c_void_p): Event manager

90

event_type (int): Event type

91

callback (function): Callback function

92

user_data (ctypes.c_void_p): User data

93

"""

94

...

95

```

96

97

### Media Functions

98

99

Low-level media object creation and manipulation functions.

100

101

```python { .api }

102

def libvlc_media_new_location(instance, mrl):

103

"""Create a media object from a media resource locator.

104

105

Args:

106

instance (ctypes.c_void_p): LibVLC instance

107

mrl (str): Media resource locator

108

109

Returns:

110

ctypes.c_void_p: Media object pointer

111

"""

112

...

113

114

def libvlc_media_new_path(instance, path):

115

"""Create a media object from a file path.

116

117

Args:

118

instance (ctypes.c_void_p): LibVLC instance

119

path (str): File path

120

121

Returns:

122

ctypes.c_void_p: Media object pointer

123

"""

124

...

125

126

def libvlc_media_new_fd(instance, fd):

127

"""Create a media object from a file descriptor.

128

129

Args:

130

instance (ctypes.c_void_p): LibVLC instance

131

fd (int): File descriptor

132

133

Returns:

134

ctypes.c_void_p: Media object pointer

135

"""

136

...

137

138

def libvlc_media_new_callbacks(instance, open_cb, read_cb, seek_cb, close_cb, opaque):

139

"""Create a media object with custom callbacks.

140

141

Args:

142

instance (ctypes.c_void_p): LibVLC instance

143

open_cb (function): Open callback

144

read_cb (function): Read callback

145

seek_cb (function): Seek callback

146

close_cb (function): Close callback

147

opaque (ctypes.c_void_p): User data

148

149

Returns:

150

ctypes.c_void_p: Media object pointer

151

"""

152

...

153

154

def libvlc_media_release(media):

155

"""Decrement the reference count of a media object.

156

157

Args:

158

media (ctypes.c_void_p): Media object pointer

159

"""

160

...

161

162

def libvlc_media_retain(media):

163

"""Increment the reference count of a media object.

164

165

Args:

166

media (ctypes.c_void_p): Media object pointer

167

"""

168

...

169

170

def libvlc_media_get_mrl(media):

171

"""Get the media resource locator.

172

173

Args:

174

media (ctypes.c_void_p): Media object pointer

175

176

Returns:

177

str: MRL string

178

"""

179

...

180

181

def libvlc_media_duplicate(media):

182

"""Duplicate a media object.

183

184

Args:

185

media (ctypes.c_void_p): Media object pointer

186

187

Returns:

188

ctypes.c_void_p: Duplicated media object pointer

189

"""

190

...

191

192

def libvlc_media_get_meta(media, meta_type):

193

"""Get metadata for a media object.

194

195

Args:

196

media (ctypes.c_void_p): Media object pointer

197

meta_type (int): Metadata type

198

199

Returns:

200

str: Metadata value or None

201

"""

202

...

203

204

def libvlc_media_set_meta(media, meta_type, value):

205

"""Set metadata for a media object.

206

207

Args:

208

media (ctypes.c_void_p): Media object pointer

209

meta_type (int): Metadata type

210

value (str): Metadata value

211

"""

212

...

213

214

def libvlc_media_save_meta(media):

215

"""Save metadata to the media file.

216

217

Args:

218

media (ctypes.c_void_p): Media object pointer

219

220

Returns:

221

bool: True on success

222

"""

223

...

224

225

def libvlc_media_get_state(media):

226

"""Get the current state of a media object.

227

228

Args:

229

media (ctypes.c_void_p): Media object pointer

230

231

Returns:

232

int: Media state

233

"""

234

...

235

236

def libvlc_media_get_duration(media):

237

"""Get the duration of a media object.

238

239

Args:

240

media (ctypes.c_void_p): Media object pointer

241

242

Returns:

243

int: Duration in milliseconds

244

"""

245

...

246

247

def libvlc_media_parse(media):

248

"""Parse a media object synchronously.

249

250

Args:

251

media (ctypes.c_void_p): Media object pointer

252

"""

253

...

254

255

def libvlc_media_parse_async(media):

256

"""Parse a media object asynchronously.

257

258

Args:

259

media (ctypes.c_void_p): Media object pointer

260

"""

261

...

262

263

def libvlc_media_parse_with_options(media, parse_flag, timeout):

264

"""Parse a media object with options.

265

266

Args:

267

media (ctypes.c_void_p): Media object pointer

268

parse_flag (int): Parse options

269

timeout (int): Timeout in milliseconds

270

271

Returns:

272

int: Parse status

273

"""

274

...

275

276

def libvlc_media_get_parsed_status(media):

277

"""Get the parsed status of a media object.

278

279

Args:

280

media (ctypes.c_void_p): Media object pointer

281

282

Returns:

283

int: Parsed status

284

"""

285

...

286

```

287

288

### Media Player Functions

289

290

Low-level media player control and state management functions.

291

292

```python { .api }

293

def libvlc_media_player_new(instance):

294

"""Create a media player.

295

296

Args:

297

instance (ctypes.c_void_p): LibVLC instance

298

299

Returns:

300

ctypes.c_void_p: Media player pointer

301

"""

302

...

303

304

def libvlc_media_player_new_from_media(media):

305

"""Create a media player from a media object.

306

307

Args:

308

media (ctypes.c_void_p): Media object pointer

309

310

Returns:

311

ctypes.c_void_p: Media player pointer

312

"""

313

...

314

315

def libvlc_media_player_release(player):

316

"""Release a media player.

317

318

Args:

319

player (ctypes.c_void_p): Media player pointer

320

"""

321

...

322

323

def libvlc_media_player_retain(player):

324

"""Retain a media player.

325

326

Args:

327

player (ctypes.c_void_p): Media player pointer

328

"""

329

...

330

331

def libvlc_media_player_set_media(player, media):

332

"""Set the media for a player.

333

334

Args:

335

player (ctypes.c_void_p): Media player pointer

336

media (ctypes.c_void_p): Media object pointer

337

"""

338

...

339

340

def libvlc_media_player_get_media(player):

341

"""Get the media from a player.

342

343

Args:

344

player (ctypes.c_void_p): Media player pointer

345

346

Returns:

347

ctypes.c_void_p: Media object pointer

348

"""

349

...

350

351

def libvlc_media_player_play(player):

352

"""Play media.

353

354

Args:

355

player (ctypes.c_void_p): Media player pointer

356

357

Returns:

358

int: 0 on success, -1 on error

359

"""

360

...

361

362

def libvlc_media_player_pause(player):

363

"""Pause media playback.

364

365

Args:

366

player (ctypes.c_void_p): Media player pointer

367

"""

368

...

369

370

def libvlc_media_player_set_pause(player, do_pause):

371

"""Set pause state.

372

373

Args:

374

player (ctypes.c_void_p): Media player pointer

375

do_pause (int): 1 to pause, 0 to resume

376

"""

377

...

378

379

def libvlc_media_player_stop(player):

380

"""Stop media playback.

381

382

Args:

383

player (ctypes.c_void_p): Media player pointer

384

"""

385

...

386

387

def libvlc_media_player_is_playing(player):

388

"""Check if media is playing.

389

390

Args:

391

player (ctypes.c_void_p): Media player pointer

392

393

Returns:

394

int: 1 if playing, 0 otherwise

395

"""

396

...

397

398

def libvlc_media_player_get_state(player):

399

"""Get player state.

400

401

Args:

402

player (ctypes.c_void_p): Media player pointer

403

404

Returns:

405

int: Player state

406

"""

407

...

408

409

def libvlc_media_player_get_time(player):

410

"""Get current playback time.

411

412

Args:

413

player (ctypes.c_void_p): Media player pointer

414

415

Returns:

416

int: Time in milliseconds

417

"""

418

...

419

420

def libvlc_media_player_set_time(player, time):

421

"""Set current playback time.

422

423

Args:

424

player (ctypes.c_void_p): Media player pointer

425

time (int): Time in milliseconds

426

"""

427

...

428

429

def libvlc_media_player_get_position(player):

430

"""Get playback position.

431

432

Args:

433

player (ctypes.c_void_p): Media player pointer

434

435

Returns:

436

float: Position between 0.0 and 1.0

437

"""

438

...

439

440

def libvlc_media_player_set_position(player, position):

441

"""Set playback position.

442

443

Args:

444

player (ctypes.c_void_p): Media player pointer

445

position (float): Position between 0.0 and 1.0

446

"""

447

...

448

449

def libvlc_media_player_get_length(player):

450

"""Get media length.

451

452

Args:

453

player (ctypes.c_void_p): Media player pointer

454

455

Returns:

456

int: Length in milliseconds

457

"""

458

...

459

460

def libvlc_media_player_get_rate(player):

461

"""Get playback rate.

462

463

Args:

464

player (ctypes.c_void_p): Media player pointer

465

466

Returns:

467

float: Playback rate

468

"""

469

...

470

471

def libvlc_media_player_set_rate(player, rate):

472

"""Set playback rate.

473

474

Args:

475

player (ctypes.c_void_p): Media player pointer

476

rate (float): Playback rate

477

478

Returns:

479

int: 0 on success, -1 on error

480

"""

481

...

482

```

483

484

### Audio Functions

485

486

Low-level audio control functions.

487

488

```python { .api }

489

def libvlc_audio_get_volume(player):

490

"""Get audio volume.

491

492

Args:

493

player (ctypes.c_void_p): Media player pointer

494

495

Returns:

496

int: Volume (0-100)

497

"""

498

...

499

500

def libvlc_audio_set_volume(player, volume):

501

"""Set audio volume.

502

503

Args:

504

player (ctypes.c_void_p): Media player pointer

505

volume (int): Volume (0-100)

506

507

Returns:

508

int: 0 on success, -1 on error

509

"""

510

...

511

512

def libvlc_audio_get_mute(player):

513

"""Get mute status.

514

515

Args:

516

player (ctypes.c_void_p): Media player pointer

517

518

Returns:

519

int: 1 if muted, 0 otherwise

520

"""

521

...

522

523

def libvlc_audio_set_mute(player, mute):

524

"""Set mute status.

525

526

Args:

527

player (ctypes.c_void_p): Media player pointer

528

mute (int): 1 to mute, 0 to unmute

529

"""

530

...

531

532

def libvlc_audio_get_track_count(player):

533

"""Get audio track count.

534

535

Args:

536

player (ctypes.c_void_p): Media player pointer

537

538

Returns:

539

int: Number of audio tracks

540

"""

541

...

542

543

def libvlc_audio_get_track(player):

544

"""Get current audio track.

545

546

Args:

547

player (ctypes.c_void_p): Media player pointer

548

549

Returns:

550

int: Audio track ID

551

"""

552

...

553

554

def libvlc_audio_set_track(player, track):

555

"""Set audio track.

556

557

Args:

558

player (ctypes.c_void_p): Media player pointer

559

track (int): Audio track ID

560

561

Returns:

562

int: 0 on success, -1 on error

563

"""

564

...

565

566

def libvlc_audio_get_delay(player):

567

"""Get audio delay.

568

569

Args:

570

player (ctypes.c_void_p): Media player pointer

571

572

Returns:

573

int: Audio delay in microseconds

574

"""

575

...

576

577

def libvlc_audio_set_delay(player, delay):

578

"""Set audio delay.

579

580

Args:

581

player (ctypes.c_void_p): Media player pointer

582

delay (int): Audio delay in microseconds

583

584

Returns:

585

int: 0 on success, -1 on error

586

"""

587

...

588

589

def libvlc_audio_equalizer_new():

590

"""Create a new audio equalizer.

591

592

Returns:

593

ctypes.c_void_p: Audio equalizer pointer

594

"""

595

...

596

597

def libvlc_audio_equalizer_new_from_preset(preset):

598

"""Create an audio equalizer from preset.

599

600

Args:

601

preset (int): Preset index

602

603

Returns:

604

ctypes.c_void_p: Audio equalizer pointer

605

"""

606

...

607

608

def libvlc_audio_equalizer_release(equalizer):

609

"""Release an audio equalizer.

610

611

Args:

612

equalizer (ctypes.c_void_p): Audio equalizer pointer

613

"""

614

...

615

616

def libvlc_audio_equalizer_set_preamp(equalizer, preamp):

617

"""Set equalizer preamp.

618

619

Args:

620

equalizer (ctypes.c_void_p): Audio equalizer pointer

621

preamp (float): Preamp value in dB

622

623

Returns:

624

int: 0 on success, -1 on error

625

"""

626

...

627

628

def libvlc_audio_equalizer_get_preamp(equalizer):

629

"""Get equalizer preamp.

630

631

Args:

632

equalizer (ctypes.c_void_p): Audio equalizer pointer

633

634

Returns:

635

float: Preamp value in dB

636

"""

637

...

638

639

def libvlc_audio_equalizer_set_amp_at_index(equalizer, amp, band):

640

"""Set equalizer band amplitude.

641

642

Args:

643

equalizer (ctypes.c_void_p): Audio equalizer pointer

644

amp (float): Amplitude in dB

645

band (int): Band index

646

647

Returns:

648

int: 0 on success, -1 on error

649

"""

650

...

651

652

def libvlc_audio_equalizer_get_amp_at_index(equalizer, band):

653

"""Get equalizer band amplitude.

654

655

Args:

656

equalizer (ctypes.c_void_p): Audio equalizer pointer

657

band (int): Band index

658

659

Returns:

660

float: Amplitude in dB

661

"""

662

...

663

```

664

665

### Video Functions

666

667

Low-level video control and display functions.

668

669

```python { .api }

670

def libvlc_video_get_size(player, num):

671

"""Get video dimensions.

672

673

Args:

674

player (ctypes.c_void_p): Media player pointer

675

num (int): Video output number

676

677

Returns:

678

tuple: (width, height)

679

"""

680

...

681

682

def libvlc_video_get_width(player):

683

"""Get video width.

684

685

Args:

686

player (ctypes.c_void_p): Media player pointer

687

688

Returns:

689

int: Video width

690

"""

691

...

692

693

def libvlc_video_get_height(player):

694

"""Get video height.

695

696

Args:

697

player (ctypes.c_void_p): Media player pointer

698

699

Returns:

700

int: Video height

701

"""

702

...

703

704

def libvlc_video_get_aspect_ratio(player):

705

"""Get video aspect ratio.

706

707

Args:

708

player (ctypes.c_void_p): Media player pointer

709

710

Returns:

711

str: Aspect ratio string

712

"""

713

...

714

715

def libvlc_video_set_aspect_ratio(player, aspect):

716

"""Set video aspect ratio.

717

718

Args:

719

player (ctypes.c_void_p): Media player pointer

720

aspect (str): Aspect ratio string

721

"""

722

...

723

724

def libvlc_video_get_scale(player):

725

"""Get video scale.

726

727

Args:

728

player (ctypes.c_void_p): Media player pointer

729

730

Returns:

731

float: Video scale

732

"""

733

...

734

735

def libvlc_video_set_scale(player, scale):

736

"""Set video scale.

737

738

Args:

739

player (ctypes.c_void_p): Media player pointer

740

scale (float): Video scale

741

"""

742

...

743

744

def libvlc_video_take_snapshot(player, num, filepath, width, height):

745

"""Take video snapshot.

746

747

Args:

748

player (ctypes.c_void_p): Media player pointer

749

num (int): Video output number

750

filepath (str): Snapshot file path

751

width (int): Snapshot width

752

height (int): Snapshot height

753

754

Returns:

755

int: 0 on success, -1 on error

756

"""

757

...

758

759

def libvlc_video_get_track_count(player):

760

"""Get video track count.

761

762

Args:

763

player (ctypes.c_void_p): Media player pointer

764

765

Returns:

766

int: Number of video tracks

767

"""

768

...

769

770

def libvlc_video_get_track(player):

771

"""Get current video track.

772

773

Args:

774

player (ctypes.c_void_p): Media player pointer

775

776

Returns:

777

int: Video track ID

778

"""

779

...

780

781

def libvlc_video_set_track(player, track):

782

"""Set video track.

783

784

Args:

785

player (ctypes.c_void_p): Media player pointer

786

track (int): Video track ID

787

788

Returns:

789

int: 0 on success, -1 on error

790

"""

791

...

792

793

def libvlc_video_get_spu_count(player):

794

"""Get subtitle track count.

795

796

Args:

797

player (ctypes.c_void_p): Media player pointer

798

799

Returns:

800

int: Number of subtitle tracks

801

"""

802

...

803

804

def libvlc_video_get_spu(player):

805

"""Get current subtitle track.

806

807

Args:

808

player (ctypes.c_void_p): Media player pointer

809

810

Returns:

811

int: Subtitle track ID

812

"""

813

...

814

815

def libvlc_video_set_spu(player, spu):

816

"""Set subtitle track.

817

818

Args:

819

player (ctypes.c_void_p): Media player pointer

820

spu (int): Subtitle track ID

821

822

Returns:

823

int: 0 on success, -1 on error

824

"""

825

...

826

827

def libvlc_video_set_subtitle_file(player, filename):

828

"""Set subtitle file.

829

830

Args:

831

player (ctypes.c_void_p): Media player pointer

832

filename (str): Subtitle file path

833

834

Returns:

835

int: 0 on success, -1 on error

836

"""

837

...

838

```

839

840

### Media List Functions

841

842

Low-level media list management functions.

843

844

```python { .api }

845

def libvlc_media_list_new(instance):

846

"""Create a media list.

847

848

Args:

849

instance (ctypes.c_void_p): LibVLC instance

850

851

Returns:

852

ctypes.c_void_p: Media list pointer

853

"""

854

...

855

856

def libvlc_media_list_release(media_list):

857

"""Release a media list.

858

859

Args:

860

media_list (ctypes.c_void_p): Media list pointer

861

"""

862

...

863

864

def libvlc_media_list_retain(media_list):

865

"""Retain a media list.

866

867

Args:

868

media_list (ctypes.c_void_p): Media list pointer

869

"""

870

...

871

872

def libvlc_media_list_add_media(media_list, media):

873

"""Add media to a list.

874

875

Args:

876

media_list (ctypes.c_void_p): Media list pointer

877

media (ctypes.c_void_p): Media object pointer

878

879

Returns:

880

int: 0 on success, -1 on error

881

"""

882

...

883

884

def libvlc_media_list_insert_media(media_list, media, index):

885

"""Insert media into a list.

886

887

Args:

888

media_list (ctypes.c_void_p): Media list pointer

889

media (ctypes.c_void_p): Media object pointer

890

index (int): Index to insert at

891

892

Returns:

893

int: 0 on success, -1 on error

894

"""

895

...

896

897

def libvlc_media_list_remove_index(media_list, index):

898

"""Remove media from a list by index.

899

900

Args:

901

media_list (ctypes.c_void_p): Media list pointer

902

index (int): Index to remove

903

904

Returns:

905

int: 0 on success, -1 on error

906

"""

907

...

908

909

def libvlc_media_list_count(media_list):

910

"""Get media list count.

911

912

Args:

913

media_list (ctypes.c_void_p): Media list pointer

914

915

Returns:

916

int: Number of items in list

917

"""

918

...

919

920

def libvlc_media_list_item_at_index(media_list, index):

921

"""Get media item at index.

922

923

Args:

924

media_list (ctypes.c_void_p): Media list pointer

925

index (int): Index of item

926

927

Returns:

928

ctypes.c_void_p: Media object pointer

929

"""

930

...

931

932

def libvlc_media_list_index_of_item(media_list, media):

933

"""Get index of media item.

934

935

Args:

936

media_list (ctypes.c_void_p): Media list pointer

937

media (ctypes.c_void_p): Media object pointer

938

939

Returns:

940

int: Index of item or -1 if not found

941

"""

942

...

943

944

def libvlc_media_list_is_readonly(media_list):

945

"""Check if media list is readonly.

946

947

Args:

948

media_list (ctypes.c_void_p): Media list pointer

949

950

Returns:

951

int: 1 if readonly, 0 otherwise

952

"""

953

...

954

955

def libvlc_media_list_lock(media_list):

956

"""Lock a media list.

957

958

Args:

959

media_list (ctypes.c_void_p): Media list pointer

960

"""

961

...

962

963

def libvlc_media_list_unlock(media_list):

964

"""Unlock a media list.

965

966

Args:

967

media_list (ctypes.c_void_p): Media list pointer

968

"""

969

...

970

971

def libvlc_media_list_event_manager(media_list):

972

"""Get media list event manager.

973

974

Args:

975

media_list (ctypes.c_void_p): Media list pointer

976

977

Returns:

978

ctypes.c_void_p: Event manager pointer

979

"""

980

...

981

```

982

983

## Usage Examples

984

985

### Direct LibVLC Instance Management

986

987

```python

988

import vlc

989

import ctypes

990

991

# Create instance with direct LibVLC function

992

argc = 2

993

argv = ['--no-audio', '--quiet']

994

instance_ptr = vlc.libvlc_new(argc, argv)

995

996

print(f"LibVLC version: {vlc.libvlc_get_version()}")

997

print(f"LibVLC compiler: {vlv.libvlc_get_compiler()}")

998

999

# Create media player directly

1000

player_ptr = vlc.libvlc_media_player_new(instance_ptr)

1001

1002

# Create media directly

1003

media_ptr = vlc.libvlc_media_new_path(instance_ptr, '/path/to/video.mp4')

1004

1005

# Set media to player

1006

vlc.libvlc_media_player_set_media(player_ptr, media_ptr)

1007

1008

# Start playback

1009

result = vlc.libvlc_media_player_play(player_ptr)

1010

print(f"Play result: {result}")

1011

1012

# Check if playing

1013

is_playing = vlc.libvlc_media_player_is_playing(player_ptr)

1014

print(f"Is playing: {is_playing}")

1015

1016

# Clean up

1017

vlc.libvlc_media_release(media_ptr)

1018

vlc.libvlc_media_player_release(player_ptr)

1019

vlc.libvlc_release(instance_ptr)

1020

```

1021

1022

### Custom Media Callbacks

1023

1024

```python

1025

import vlc

1026

import ctypes

1027

1028

# Define callback functions

1029

def media_open_cb(opaque, data_pointer, size_pointer):

1030

"""Media open callback."""

1031

print("Media open callback called")

1032

# Custom media opening logic here

1033

return 0

1034

1035

def media_read_cb(opaque, buffer, length):

1036

"""Media read callback."""

1037

print(f"Media read callback: {length} bytes")

1038

# Custom media reading logic here

1039

return length

1040

1041

def media_seek_cb(opaque, offset):

1042

"""Media seek callback."""

1043

print(f"Media seek callback: offset {offset}")

1044

# Custom media seeking logic here

1045

return 0

1046

1047

def media_close_cb(opaque):

1048

"""Media close callback."""

1049

print("Media close callback called")

1050

# Custom media closing logic here

1051

1052

# Create instance

1053

instance_ptr = vlv.libvlc_new(0, None)

1054

1055

# Create media with callbacks

1056

opaque_data = ctypes.c_void_p()

1057

media_ptr = vlc.libvlc_media_new_callbacks(

1058

instance_ptr,

1059

media_open_cb,

1060

media_read_cb,

1061

media_seek_cb,

1062

media_close_cb,

1063

opaque_data

1064

)

1065

1066

# Use the media normally

1067

player_ptr = vlc.libvlc_media_player_new_from_media(media_ptr)

1068

vlc.libvlc_media_player_play(player_ptr)

1069

1070

# Clean up

1071

vlc.libvlc_media_player_release(player_ptr)

1072

vlc.libvlc_media_release(media_ptr)

1073

vlc.libvlc_release(instance_ptr)

1074

```

1075

1076

### Low-Level Event Handling

1077

1078

```python

1079

import vlc

1080

import ctypes

1081

1082

# Event callback function

1083

def event_callback(event_ptr, user_data):

1084

"""Low-level event callback."""

1085

# Access event structure directly

1086

event = ctypes.cast(event_ptr, ctypes.POINTER(vlc.Event)).contents

1087

print(f"Event type: {event.type}")

1088

1089

# Handle specific event types

1090

if event.type == vlc.EventType.MediaPlayerPlaying:

1091

print("Player started playing")

1092

elif event.type == vlc.EventType.MediaPlayerPaused:

1093

print("Player paused")

1094

elif event.type == vlc.EventType.MediaPlayerStopped:

1095

print("Player stopped")

1096

1097

# Create instance and player

1098

instance_ptr = vlc.libvlc_new(0, None)

1099

player_ptr = vlc.libvlc_media_player_new(instance_ptr)

1100

1101

# Get event manager

1102

player_obj = vlc.MediaPlayer._from_instance(player_ptr)

1103

event_manager_ptr = player_obj.event_manager()._as_parameter_

1104

1105

# Attach event directly

1106

user_data = ctypes.c_void_p()

1107

result = vlc.libvlc_event_attach(

1108

event_manager_ptr,

1109

vlc.EventType.MediaPlayerPlaying,

1110

event_callback,

1111

user_data

1112

)

1113

print(f"Event attach result: {result}")

1114

1115

# Create and play media

1116

media_ptr = vlc.libvlc_media_new_path(instance_ptr, '/path/to/video.mp4')

1117

vlc.libvlc_media_player_set_media(player_ptr, media_ptr)

1118

vlc.libvlc_media_player_play(player_ptr)

1119

1120

# Wait for events

1121

import time

1122

time.sleep(5)

1123

1124

# Detach event

1125

vlc.libvlc_event_detach(

1126

event_manager_ptr,

1127

vlc.EventType.MediaPlayerPlaying,

1128

event_callback,

1129

user_data

1130

)

1131

1132

# Clean up

1133

vlc.libvlc_media_player_stop(player_ptr)

1134

vlc.libvlc_media_release(media_ptr)

1135

vlc.libvlc_media_player_release(player_ptr)

1136

vlc.libvlc_release(instance_ptr)

1137

```

1138

1139

### Advanced Audio Control

1140

1141

```python

1142

import vlc

1143

import ctypes

1144

1145

# Create player

1146

instance_ptr = vlc.libvlc_new(0, None)

1147

player_ptr = vlc.libvlc_media_player_new(instance_ptr)

1148

media_ptr = vlc.libvlc_media_new_path(instance_ptr, '/path/to/audio.mp3')

1149

vlc.libvlc_media_player_set_media(player_ptr, media_ptr)

1150

1151

# Start playback

1152

vlc.libvlc_media_player_play(player_ptr)

1153

1154

# Direct audio control

1155

current_volume = vlc.libvlc_audio_get_volume(player_ptr)

1156

print(f"Current volume: {current_volume}")

1157

1158

# Set volume directly

1159

vlc.libvlc_audio_set_volume(player_ptr, 75)

1160

print(f"Volume set to: {vlc.libvlc_audio_get_volume(player_ptr)}")

1161

1162

# Mute control

1163

vlc.libvlc_audio_set_mute(player_ptr, 1) # Mute

1164

print(f"Muted: {vlc.libvlc_audio_get_mute(player_ptr)}")

1165

1166

vlc.libvlc_audio_set_mute(player_ptr, 0) # Unmute

1167

print(f"Muted: {vlc.libvlc_audio_get_mute(player_ptr)}")

1168

1169

# Audio track control

1170

track_count = vlc.libvlc_audio_get_track_count(player_ptr)

1171

print(f"Audio tracks: {track_count}")

1172

1173

current_track = vlc.libvlc_audio_get_track(player_ptr)

1174

print(f"Current track: {current_track}")

1175

1176

# Audio delay control

1177

current_delay = vlc.libvlc_audio_get_delay(player_ptr)

1178

print(f"Current audio delay: {current_delay}")

1179

1180

vlc.libvlc_audio_set_delay(player_ptr, 100000) # 100ms delay

1181

print(f"New audio delay: {vlc.libvlc_audio_get_delay(player_ptr)}")

1182

1183

# Create and use equalizer

1184

equalizer_ptr = vlc.libvlc_audio_equalizer_new()

1185

1186

# Set preamp

1187

vlc.libvlc_audio_equalizer_set_preamp(equalizer_ptr, 2.0)

1188

preamp = vlc.libvlc_audio_equalizer_get_preamp(equalizer_ptr)

1189

print(f"Equalizer preamp: {preamp}")

1190

1191

# Set band levels

1192

for band in range(10): # 10-band equalizer

1193

vlc.libvlc_audio_equalizer_set_amp_at_index(equalizer_ptr, 1.0, band)

1194

amp = vlc.libvlc_audio_equalizer_get_amp_at_index(equalizer_ptr, band)

1195

print(f"Band {band}: {amp}dB")

1196

1197

# Clean up

1198

vlc.libvlc_audio_equalizer_release(equalizer_ptr)

1199

vlc.libvlc_media_player_stop(player_ptr)

1200

vlc.libvlc_media_release(media_ptr)

1201

vlc.libvlc_media_player_release(player_ptr)

1202

vlc.libvlc_release(instance_ptr)

1203

```

1204

1205

### Memory Management Example

1206

1207

```python

1208

import vlc

1209

import ctypes

1210

1211

# Create instance with retain/release

1212

instance_ptr = vlc.libvlc_new(0, None)

1213

vlc.libvlc_retain(instance_ptr) # Increment reference count

1214

1215

# Create media with retain/release

1216

media_ptr = vlc.libvlc_media_new_path(instance_ptr, '/path/to/video.mp4')

1217

vlc.libvlc_media_retain(media_ptr) # Increment reference count

1218

1219

# Duplicate media

1220

duplicate_ptr = vlc.libvlc_media_duplicate(media_ptr)

1221

1222

# Create player with retain/release

1223

player_ptr = vlc.libvlc_media_player_new(instance_ptr)

1224

vlc.libvlc_media_player_retain(player_ptr) # Increment reference count

1225

1226

# Use media and player

1227

vlc.libvlc_media_player_set_media(player_ptr, media_ptr)

1228

vlc.libvlc_media_player_play(player_ptr)

1229

1230

import time

1231

time.sleep(5)

1232

1233

# Proper cleanup with reference counting

1234

vlc.libvlc_media_player_stop(player_ptr)

1235

1236

# Release all references

1237

vlc.libvlc_media_player_release(player_ptr) # Decrement

1238

vlc.libvlc_media_player_release(player_ptr) # Final release

1239

1240

vlc.libvlc_media_release(duplicate_ptr)

1241

vlc.libvlc_media_release(media_ptr) # Decrement

1242

vlc.libvlc_media_release(media_ptr) # Final release

1243

1244

vlc.libvlc_release(instance_ptr) # Decrement

1245

vlc.libvlc_release(instance_ptr) # Final release

1246

1247

print("All references properly released")

1248

```