0

When i try to run this code :

import cv2
import vlc
cam = cv2.VideoCapture(0)
m = vlc.MediaPlayer('D:\faith-42201.mp3')
fd = cv2.CascadeClassifier(r'C:\Users\Shivani Khare\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\cv2\data\haarcascade_frontalface_alt.xml')
m.play()
flag=1
m.audio_set_volume(100)
while(True):
    r,i = cam.read()
    #i[0:10,:,:]=255
    #for adding rows
    j = cv2.cvtColor(i,cv2.COLOR_BGR2GRAY)
    face = fd.detectMultiScale(j,1.3,7)
    for (x,y,w,h) in face:
        cv2.rectangle(i,(x,y),(x+w,y+h),(0,0,0),-1)
        t = w*h
        m.audio_set_volume(100-int(t/500))
        l = len(face)
        if(l>0):
            m.play()
            flag = 0
        elif(flag==0):
            m.pause()
            flag = 1
    print("no of faces are : ",len(face),face)
    cv2.imshow('image1',i)

    k = cv2.waitKey(5)
    print(k)
    if(k==27):
        cv2.destroyAllWindows()
        break

I keep getting this error :

Traceback (most recent call last):

File "C:\Users\Shivani Khare\AppData\Local\Programs\Python\Python36\hi.py", line 5, in m = vlc.MediaPlayer('D:\faith-42201.mp3') File "C:\Users\Shivani Khare\AppData\Local\Programs\Python\Python36\lib\site-packages\vlc.py", line 3184, in new o.set_media(instance.media_new(*args)) File "C:\Users\Shivani Khare\AppData\Local\Programs\Python\Python36\lib\site-packages\vlc.py", line 1788, in media_new m._instance = self AttributeError: 'NoneType' object has no attribute '_instance'

Please help

1 Answer 1

1

You're passing a list in MediaPlayer constructor in line#5, but it expects a string(ref: https://linuxconfig.org/how-to-play-audio-with-vlc-in-python).

Try making this change:

m = vlc.MediaPlayer('D:\faith-42201.mp3')
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you @devender22. But I had changed that already, I am still getting the same error. My python version is 3.6.6
It's working fine in mac env(as file names don't have ":" in them) In [9]: vlc.MediaPlayer('D:\faith-42201.mp3') # till this point no file is read Out[9]: <vlc.MediaPlayer at 0x1046abe50> Can you try to debug this in your m/c like this: In [5]: import pdb In [7]: pdb.run('''vlc.MediaPlayer('D:\faith-42201.mp3')''') > <string>(1)<module>() (Pdb) b <local vlc lib path in your m/c>vlc.py:3184 It has this method media_new which is getting m variable as None. This method treats the file path containing ":" as url path..
I can try to help if you provide more details what is happening in your env
Change all of those backslashes to forward slashes, to avoid accidentally mangling strings. Python on Windows will cope with that just fine. it might not be your problems, or it might be causing some internal confusion that's masking your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.